The present research utilizes a sol-gel approach to create a CoFe2O4/g-C3N4 nanocomposite (NC) and explored several analytical methods to evaluate physical, chemical and optical based characteristics via XRD, FTIR, UV–vis, SEM/EDS and XPS for the prepared pure CoFe2O4, g-C3N4, and CoFe2O4/g-C3N4 NC. The XRD results show that the prepared g-C3N4, CoFe2O4, exhibits hexagonal and cubic phases respectively, whereas the g-C3N4/CoFe2O4 NC exhibit mixing of two phases. The energy band gaps for pure g-C3N4, CoFe2O4 and g-C3N4/CoFe2O4 NC values are viz., 2.75, 1.3, and 2.4 eV. As photocatalysts, synthesized materials were utilized for the decomposition of Rhodamine-B (RhB) dye. Finally, the CoFe2O4/g-C3N4 NC showed good performance of photocatalysis for RhB dye disintegration under the stimulus of visible light. According to the induced visible light, the rate at which the photocatalytic degradation occurs for the CoFe2O4/g-C3N4 NC was found to be 57% in 120 min and this is greater when compared with pure catalysts like CoFe2O4 (28%) and g-C3N4 (10%). These outcomes suggest that the prepared NC have efficiently worked during the photocatalytic process compared with its pure materials.