Searching for highly efficient bifunctional oxygen evolution reaction/oxygen reduction reaction (OER/ORR) electrocatalysts for sustainable and renewable clean energy is vital. However, these electrocatalyst designs remain cost-prohibitive for both experimental and computational studies. This paper systematically investigates 5d transition metal (5d TM) doped into graphitic carbon nitride (g-C3N3) as potential bifunctional OER/ORR electrocatalysts by considering the defect charge states through the defect chemistry study. Our formation energies results show that 33 kinds of 5d TM doped g-C3N3 have better stabilities in the different charge states. Among them, IrN×@C54N53 (Ir occupation N), IrN•@C54N53, PtN×@C54N53 (Pt occupation N), and Iri•@C54N54 (Ir interstitial sites) exhibit lower overpotentials. They are great candidates for bifunctional OER/ORR electrocatalysts. This is because adjusting the charge states of 5d-TM@g-C3N3 can tune the interaction strength of the oxygenated intermediates. Furthermore, machine learning shows that the charge transfer of TM atoms (Qe) and total magnetic moment (μB0) are the two most essential descriptors for OER and ORR overpotential, respectively. The charged defect adjusting of the bifunctional OER/ORR activity would develop the potential electrocatalysts for energy conversion applications.