Molecular orbitals of nitrogen and oxygen is as below:
Nitrogen molecule has 14 electrons. So the electron distributions in molecular orbital are as below
N2 = σ1s2 σ*1s2 σ2s2 σ*2s2 σ2px2 π(2py2 2pz2)
Bond order = (No. of electrons in bonding orbitals - No. of electrons in bonding orbitals)/2
=(10-4)/2 = 3
Oxygen molecule has 16 electrons. So the electron distributions in molecular orbital are as below
O2 = σ1s2 σ*1s2 σ2s2 σ*2s2 σ2px2 π(2py2 2pz2) π*(2py1 2pz1)
Bond order= (10-6)/2 = 2
As bond order of nitrogen is more than that of oxygen, nitrogen is more stable than oxygen.