The CO2 electrochemical reduction reaction (CO2RR) has been a promising conversion method for CO2 utilization. Currently, the lack of electrocatalysts with favorable stability and high efficiency hindered the development of CO2RR. Nitrogen-doped graphene nanocarbons have great promise in replacing metal catalysts for catalyzing CO2RR. By using the density functional theory (DFT) method, the catalytic mechanism and activity of CO2RR on 11 types of nitrogen-doped graphene have been explored. The free energy analysis reveals that the zigzag pyridinic N- and zigzag graphitic N-doped graphene possess outstanding catalytic activity and selectivity for HCOOH production with an energy barrier of 0.38 and 0.39 eV, respectively. CO is a competitive product since its free energy lies only about 0.20 eV above HCOOH. The minor product is CH3OH and CH4 for the zigzag pyridinic N-doped graphene and HCHO for zigzag graphitic N-doped graphene, respectively. However, for Z-pyN, CO2RR is passivated by too strong HER. Meanwhile, by modifying the pH value of the electrolyte, Z-GN could be selected as a promising nonmetal electrocatalyst for CO2RR in generating HCOOH.