We describe a novel approach to prepare nitrogen-doped carbon nanofibers for applications in electrochemistry. Freestanding carbon nanofibers (NCNFs) were first prepared by the carbonization of electrospun PVP nanofibers. Effective nitrogen doping was subsequently achieved by thermal treatment of the PVP-based carbon nanofibers via the pyrolysis of g-C3N4. The nitrogen content in the NCNFs was tuned from 6.37 to 13.72 at% via the treatment temperature. A surface adsorption and internal diffusion process helped explain the doping mechanism via thermogravimetric analysis/Fourier-transform infrared spectroscopy (TGA/FTIR) and X-ray photoelectron spectroscopy (XPS) analysis. The NCNFs obtained at 800 degrees C showed suitable nitrogen contents, good conductivities, and high electrochemical performances. The NCNFs exhibited a markedly enhanced specific capacitance of 265 F/g at a current density of 1 A/g. This is about ten times that of pure PVP-based carbon nanofibers (26 F/g at 1 A/g). They also exhibited a high rate capability (131 F/g at 16 A/g) and excellent stability. The contributions of the pyridinic N state to the pseudo-capacitances and the contribution of the quaternary N state to the conductivity produced synergistic effects leading to the improved electrochemical properties. In addition, a high cell capacitance of 32 F/g was achieved at a current density of 0.5 A/g based on the obtained NCNFs. The new nitrogen doping strategy can likely be used to obtain other types of nitrogen-doped carbon materials or nitrogen-doped semiconductors. (C) 2019 Elsevier Ltd. All rights reserved.