In a single step, nitrogen‐doped activated carbons have been synthesized using walnut shells and urea as precursors by chemical activation with K2CO3. The textural and elemental properties such as surface area, micropore volume, nitrogen content, and yield were optimized in a multivariable way using a central composite design of experiments 23, varying the urea‐nutshell ratio, K2CO3 ratio, and activation temperature. Activated carbon doped with the highest nitrogen presented a surface area of 895 m2 g−1, a micropore volume of 0.22 cm3 g−1, and a nitrogen content of 4.11 %. Furthermore, the yield of 13.85 % at urea impregnation ratio 1.56 gUrea gNutshell−1, activating agent ratio 1.4 gK2CO3 gCarbon−1, and temperature of 591 °C, being the temperature and the urea impregnation ratio the significant variables in the responses evaluated. The best‐activated carbon doped with nitrogen presented a CO2 adsorption capacity of 2.78 mol kg−1, reversible adsorption‐desorption, and selectivity against nitrogen of 33.2 molCO2/molN2, superior to a commercial activated carbon with similar textural properties at the same experimental conditions and being in the order of magnitude as activated carbons synthesized under similar conditions.