In this research, graphitic carbon nitride (g–C3N4)–cobalt ferrite (CFO) and g–C3N4– Ca, Mg codoped CFO composite with and without ZnO nanoparticles were fabricated by a combination of hydrothermal and freeze-drying methods. The effects of CFO nanoparticles to graphitic carbon nitride (carbon azide or g-C3N4) nanosheets weight ratio on the microstructure, phase evolution, magnetic, and electromagnetic (EM) behavior of g–C3N4– CFO–ZnO nanocomposite were investigated. The results revealed Ca-, and Mg-codoped CoFe2O4 nanoparticles were obtained by the green synthesis method. Moreover, as-prepared g–C3N4– CFO–ZnO nanocomposite had lamella structures. The sample prepared with Ca-, Mg-codoped CFO: g-C3N4 = 2:1 with an effective thickness of 10 mm absorbed more than 90% of EM waves in both the X-band (frequency 8.2–12.4 GHz) and Ku-band (12.4–18 GHz). Finally, the proposed mechanism of EM absorption was suggested. Finally, the effect of ZnO nanoparticles on the EM wave behavior of g–C3N4– CFO nanocomposite was investigated.