In this study, nitrogen and fluorine co-doped carbon nanocages (NF-CNCs) were synthesized as anode materials for potassium- ion batteries (KIBs), and their structural evolution with heat treatment and electrochemical behavior with different functional groups was investigated. NF-CNCs were prepared by physically mixing coal tar pitch (CTP) with a SiO2 template, followed by heat treatment and subsequent fluorination with NF3 gas. A systematic investigation of the structural properties revealed that graphitization increased with increasing heat treatment temperature as the carbon structure transitioned from amorphous at 500 and 1000 °C to graphite-like at 1500 °C. Furthermore, nitrogen and fluorine functional group analysis revealed significant changes, particularly in terms of covalent and semi-ionic C‒F bonds. Among the samples, NF-CNC 1000 displayed excellent electrochemical performance, with a specific capacity of 395.1 mAh g− 1 and a capacity retention rate of 94% during 1000 cycles at 50 mA g− 1. The exceptional performance of NF-CNC 1000 is attributed to its high porosity, amorphous carbon structure, and semi-ionic C‒F bonds, which facilitate the efficient adsorption and intercalation of potassium ions. These findings provide valuable insights into the design of advanced anode materials for next-generation KIBs.