The origin of nitrogen ionization in the upper atmosphere