In this paper, the electronic structures and absorption spectra of LiNbO3 (LN) and Fe:Mg:LiNbO3 crystals are studied by the first-principles under the generalized gradient approximation. The supercell structures of the LN crystal are established with 60 atoms, including four models: pure LN crystal, Fe:LiNbO3 crystal (Fe:LN), Fe:Mg:LiNbO3 crystal with Mg of 2 mol%-3 mol% (Fe:Mg(L):LN), and Fe:Mg:LiNbO3 crystal with Mg of 5.0 mol% (Fe:Mg(E):LN). The electronic structures show that the extrinsic defect levels (within forbidden band) of Fe:LN are contributed by Fe 3d orbital and O 2p orbital, and the band gap of Fe:LN (about 2.85 eV) is narrower than that of LN. For Fe:Mg:LN crystals, the band gap changes to 2.90 eV and 2.81 eV respectively for the Mg ion concentration less than and equal to the threshold (~5.0 mol%). The two absorption peaks at 2.3 eV and 2.6 eV are attributed to the Fe ions in crystal. Moreover, the intensities of these peaks vary with the concentration of Mg ion. It is revealed that the concentration of Mg ion influences the concentrations and the sites of Fe2+ and Fe3+ ions in crystal. From the absorption spectrum, the values of ratio Fe2+/Fe3+ in Fe:Mg(E):LN and Fe:Mg(L):LN can be obtained, and the ratio of first sample is smaller than that of the second one. With the one-center model, one can distinctly deduce that the photoconductivity of Fe:Mg(E):LN is relatively weak compared with that of Fe:Mg(L):LN, but this is inconsistent with many experimental results. One notices the contribution of O 2p orbital to extrinsic defect level in electronic structure. Therefore, it is reasonable to presume that the one-center model is not suitable enough for this condition. Based on the research work, we find that the formations of photoelectrons are related to orbital electron states of iron ions and oxygen atoms at extrinsic defect levels in Fe:LN and Fe:Mg:LN crystals.