Porous nitrogen-doped carbon is an especially promising material energy storage due to its excellent conductivity, stable physicochemical properties, easy processability, controllable porosity and low price. Herein, we reported a novel well-designed hierarchically porous nitrogen-doped carbon (HPNC) via a combination of salt template (ZnCl2) and hard template (SiO2) as sulfur host for lithium–sulfur batteries. The low-melting ZnCl2 is boiled off and leaves behind micropores and small size mesopores during pyrolysis process, while the silica spheres are removed by acid leaching to generate interconnected 3D network of macropores. The HPNC-S electrode exhibits an initial specific capacity of 1355 mAh g–1 at 0.1 C (1 C = 1675 mAh g–1), a high-rate capability of 623 mAh g–1 at 2 C, and a small decay of 0.13% per cycle over 300 cycles at 0.2 C. This excellent rate capability and remarkable long-term cyclability of the HPNC-S electrode are attributed to its hierarchical porous structures for confining the soluble lithium polysulfide as well as the nitrogen doping for high absorbability of lithium polysulfide.