Four new N,S-codoped hierarchically porous carbons (NSHPCs) with similar sulfur content while obviously different nitrogen content and ratio of micropore volume to total pore volume (Vmicro/Vtot) are synthesized. It is found that the nitrogen content and the Vmicro/Vtot ratio of NSHPCs increase with the increasing of the mass ratio of thiourea to CaCl2. Electrochemical results indicate that reasonable N-doping level is favorable to enhancing the intrinsic capacitance, but excessive high N-doping level leads to many defect sites and then increases the charge transfer resistance; furthermore, the Vmicro/Vtot ratio displays an important effect on determining the rate performance of NSHPCs. Thus the NS-132 sample, obtained from the pyrolysis of the a mixed precursor containing of sugar bagasse, CaCl2 and thiourea in a mass ratio of 1:3:2 at 800 °C for 2 h, possesses nitrogen content of 8.67 atm% and Vmicopore/Vtotal ratio of 46.6% and displays the best capacitive performance. It exhibits high specific capacitances of 357.8, 376.4 and 237.8 F g−1 in 6 M KOH, 1 M H2SO4 and 2 M Li2SO4 at 1.0 A g−1, respectively. A symmetric capacitor prepared from the NS-132-based electrodes displays high energy, good power densities (18.0 Wh⋅kg−1 at 16.9 kW kg−1) and 95.4% capacitance retention capability after 10 000 cycles at 10.0 A g−1 in 2.0 M Li2SO4 electrolyte. These results provide a guidance for the structure design and an easy synthesis route for the NSHPCs with high electrochemical performance.