Abstract The total nitrogen budget in the Martian upper atmosphere is significantly contributed by the presence of odd nitrogen, mainly in the form of NO and ground-state or excited-state N. The distribution of these species can be effectively probed by airglow emission on Mars, and understanding such a distribution is crucial for unveiling the thermal balance in the Martian upper atmosphere. In this study, we construct a sophisticated 1D photochemical model that also incorporates vertical diffusion and photoelectron production and transport. Such a model is used for obtaining the atmospheric distribution of both NO and different electronic states of atomic N on the dayside of Mars. Our study reproduces well the available measurements of relevant species in the combined Martian upper atmosphere and ionosphere, disentangling various chemical pathways in their contributions to odd nitrogen production and destruction. In addition, the photochemical model is combined with a Monte Carlo kinetic model to derive the dayside total N escape rate to be 3.3 × 10 23 s −1 driven by photochemistry. This study corroborates previous findings that N 2 photolysis and N