Due to its excellent anchoring properties to lithium polysulfide (LiPSs), g-C3N4 has been widely studied as anode material for lithium‑sulfur batteries (LSBs). g-C3N4 as the electrode material has an obvious irreversible capacity during the initial discharge progress. The mechanism of this irreversible reaction and its effect on the adsorption of LiPSs and cycling performance of g-C3N4 are not clear. Using first-principle calculations, founding that during the initial discharge progress, the binding energy of lithium to the heptazine ring is larger than the binding energy of lithium to sulfur resulting in this part of lithium entering the center of the heptazine ring and being unable to desorption form Li@g-C3N4, which is the main reason for the irreversible capacity. However, compared with g-C3N4, the conductivity of Li@g-C3N4 is enhanced and the diffusion of lithium atoms is facilitated not only by avoiding the strong interaction of other Li atoms with g-C3N4 because the vacancies have been filled. And the adsorption of LiPSs is also appropriately weakened, which can better maintain the structure integrity of the Li2S6 and Li2S8 molecules and lead to a lower reaction free energy during the discharge process.