We propose a new synthetic route towards nanoporous functional carbon materials based on salt templating with pore-padding approach (STPP). STPP relies on the use of a pore-padding agent that undergoes an initial polymerisation/ condensation process prior to the formation of a solid carbon framework. The pore-padding agent allows tailoring hierarchically the pore-size distribution and controlling the amount of heteroatom (nitrogen in this case) functionalities as well as the type of nitrogen (graphitic, pyridinic, oxides of nitrogen) incorporated within the carbon framework in a single-step-process. Our newly developed STPP method offers a unique pathway and new design principle to create simultaneously high surface area, microporosity, functionality and pore hierarchy. The functional carbon materials produced by STPP showed a remarkable CO2/N2 selectivity. At 273 K, a carbon with only micropores offered an exceptionally high CO2 adsorption capacity whereas a carbon with only mesopores showed promising CO2-philicity with high CO2/N2 selectivity in the range of 46–60 %, making them excellent candidates for CO2 capture from flue gas or for CO2 storage.