Nitrogen-doped porous carbon (NPC) was prepared by directly carbonizing zeolite ZSM-39 containinga structure-directing agent, tetramethylammonium chloride (TMACl), which also acted as a source of Cand N for NPC. The cage-like pore of zeolite ZSM-39 acted as an ideal space for immobilizing the C andN species. The obtained NPCs have a high N content up to 18.14%. The quaternary N of template TMAClwas transformed into pyridinic and pyrrolic/pyridonic N during the carbonization. NPCs were suitable forselective adsorption of CO2 because of their unique ultra-micropores and abundant basic sites. Theadsorption selectivity of CO2 over N2 was more than 12.1 (molar ratio). The CO2 adsorption capacity ofthe unit surface area for a NPC-723 sample was calculated as 26.6 mmol m2 at 0.93 bar and 273 K,which is one of the highest values among carbon adsorbents. Its excellent selectivity makes the NPCa good candidate for separating low concentrations of CO2 in the purification of gas mixtures.