Nitrogen and oxygen co-doped porous carbon network is synthesized by NaCl template-assisted in situ confinement method and used for a high-performance sodium-ion battery anode.