Nitrogen-enriched carbons with hierarchical pore structures were prepared by the direct pyrolysis of melamine resin and poly(vinylidene fluoride) (PVDF) in an inert atmosphere. Our preparation method produced carbons that feature high micropore surface areas of up to 966 m2 g−1, with the peak micropore width around 0.5–0.6 nm, and 3–4 nm mesopore channels without the need for a template or activation post-carbonization. The carbons were characterized using N2 and CO2 sorption analyses, X-ray photoelectron spectroscopy and elemental analysis. The concentrations of nitrogen at the carbon surface were in the range 3.1–4.5 at.%. The electrochemical performance of carbon electrodes was evaluated using cyclic voltammetry, galvanostatic charge-discharge techniques and impedance spectroscopy in 1 M H2SO4 and 1 M TEABF4/acetonitrile. Electrochemical tests in aqueous electrolyte showed excellent rate performance with capacitive behaviour up to 500 mV s−1 and a specific capacitance of 125 F g−1 at the current density of 0.05 A g−1 in a two-electrode cell. In both aqueous and organic electrolytes, good cycling performance are obtain with 96% and 77% of the initial capacitance after 10,000 and 5000 cycles, respectively.