A new approach for synthesizing heteroatom-doped carbon nanostructures has been developed, in which nitrogen and oxygen have been effectively infused into the graphitic core using the required precursors. The heteroatoms incorporated into the carbon matrix and their corresponding structural features are examined. The observed X-ray diffraction pattern reveals the presence of amorphous carbon forms that resemble carbon nitride in their structure. The presence of additional N–O and C–O bonds gives strong evidence of a graphitic structure with oxygen and nitrogen incorporation, as shown by the Fourier transform-infrared peaks. The X-ray photoelectron spectroscopy analysis reveals important information regarding the bond formation in the graphitic core of the sample. The study focused on examining the porous and intricately interconnected network structures, showcasing a variety of particle morphologies, and was carried out using scanning electron and transmission electron microscopy. The lattice defects are investigated using transmission electron microscopy-high angle annular dark field technique to explore the surface morphology. The influence of incorporated O and N in carbon structure drastically reduced the electron density of the graphitic core. As a result, the absorption bands observed were around 300–400 nm, showing the semiconductors' absorption characteristics. Three-electrode electrochemical systems are fabricated with working electrodes based on COx and CNx materials. The COx and CNx-modified electrodes were meticulously tested for their performance in supercapacitor applications. The COx samples exhibit a significant specific capacity value of 439.20 C g−1 under a low current density of 4 A g−1. The CNx samples demonstrate a specific capacity of 420.00 C g−1 under 4 A g−1 current density.