The design of novel porous solid sorbents for carbon dioxide capture is critical in developing carbon capture and storage technology (CCS). We have synthesized a series of nitrogen-rich porous organic polymers (POPs) from crosslinking melamine and pyrrole monomers. The final polymer’s nitrogen content was tuned by varying the melamine ratio compared to pyrrole. The resulting polymers were then pyrolyzed at 700 °C and 900 °C to produce high surface area nitrogen-doped porous carbons (NPCs) with different N/C ratios. The resulting NPCs showed good BET surface areas reaching 900 m2g−1. Owing to the nitrogen-enriched skeleton and the micropore nature of the prepared NPCs, they exhibited CO2uptake capacities as high as 60 cm3g−1at 273 K and 1 bar with significant CO2/N2selectivity. The materials showed excellent and stable performance over five adsorption/desorption cycles in the dynamic separation of the ternary mixture of N2/CO2/H2O. The method developed in this work and the synthesized NPCs’ performance towards CO2capture highlight the unique properties of POPs as precursors for synthesizing nitrogen-doped porous carbons with a high nitrogen content and high yield.