Previous research has proven that the pore shape and nitrogen group content of adsorbents play essential roles in determining their carbon dioxide (CO2) adsorption performance. In this article, a series of nitrogen-doped porous carbon materials were prepared for CO2 adsorption by varying the proportion of carbon nitride, the pyrolysis temperature, and the activation ratio of KOH, using chitosan as the carbon source, carbon nitride (g-C3N4 and g-C3N5) as self-sacrificing templating agents, and KOH as the activator. Among the prepared materials, T6-850-1 has the highest specific surface area (SBET) of 2336 m2/g, and T6-750-1 has the highest microporous area (Smicro) and CO2 adsorption capacity (1 bar, 298 K) of 1969 m2/g and 3.49 mmol/g, respectively. The thermal decomposition temperature and products of carbon nitride templates were characterized and tested by thermogravimetric infrared gas chromatography-mass spectrometry (TG-IR-GC-MS), and the thermal decomposition mechanisms of the two carbon nitride templates were investigated. We found that the thermal stability of the template directly affects the pore structure of the final sample as well as the type and quantity of nitrogen species.