Abstract A synthetic strategy for preparing nitrogen (N)-doped porous carbons with high electrochemical performance is proposed using peanut shell as the raw material and melamine as the dopant. The as-prepared activated carbons exhibit a hierarchical porous structure with abundant micropores and mesopores, and the mesopores are mainly in the pore size range of 2 and 5 nm. The N-doping leads to the formation of nitrogen-containing functional groups on the surface of the activated carbons. The optimum sample in this work is obtained at a melamine to activated carbon mass ratio of 2:1 (NHAC-2), which possesses a high surface area of 2014.6 m2/g. The assembled NHAC-2 based electrode delivers a high specific capacitance of 310.59 F/g at the current density of 0.5 A/g in the three-electrode system. In the two-electrode system, the symmetric supercapacitor assembled by NHAC-2 demonstrates a high specific capacitance of 300.6 F/g at 0.5 A/g and 246.4 F/g at 10 A/g, exhibiting high capacitance retention. NHAC-2 also exhibits excellent cycle stability with the capacitance retention of 90.14% after 5,000 cycles at the current density of 2 A/g.