The spin-polarized plane-wave pseudopotential method, based on density-functional theory, has been used to calculate the electronic band structures and the optical absorption spectra of nitrogen-doped and oxygen-deficient anatase TiO2. The calculated results are in good agreement with our experimental measurements. These ab initio calculations reveal that the optical absorption of nitrogen-doped TiO2 in the visible light region is primarily located between 400 and 500 nm, while that of oxygen-deficient TiO2 is mainly above 500 nm. These results have important implications for the understanding and further development of photocatalytic materials that are active under visible light.