• Pyrrolic N enhances charge storage capacity at high frequencies due to higher adsorption energy.
• Graphitic N improves ion response speed at high frequencies due to lower adsorption energy.
• Adsorption energy is proposed as a universal descriptor for designing high-frequency supercapacitor electrodes.
• Gradient carbonization of melamine foam enables controlled surface N configurations for optimized performance.