It becomes an effective way to solve environmental pollution by using photocatalysis of semiconductors. For the reasons of chemical stabilization and unique electronic structure, polymeric graphitic carbon nitride (g-C3N4) has been used extensively in the field of photocatalysis. Using the first principle calculations, optimized crystal structures and electronic structures are calculated for the doped cases. From comparisons of formation energies, the most stable crystal structures are obtained for monatomic substitutional doping cases and polyatomic surface transfer doping ones. The results reveal that C/g-C3N4 can be easier synthetized than N/g-C3N4 because of its lower formation energy. The results show that the best doping ratio of C is 1/12 for the reason of high visible light response. The calculated results are helpful to provide theoretical basis and instruction for subsequent synthesis in addition to the microscopic mechanism of doping.