Hund's rules
Hund's rule of maximum multiplicity
Hund's first rule states that the lowest energy atomic state is the one that maximizes the total spin quantum number for the electrons in the open subshell (which also maximizes Spin multiplicity). Maximization in this context means trying to achieve as negative/positive as it can. Therefore electrons will occupy empty orbitals (and become unpaired) first. This is because even though they have opposite spins and can share an orbital, there remains an electrostatic repulsion between them because they are both negatively charged. This repulsion increases the energy of the system.
Due to the Pauli's Exclusion principle, two electrons cannot share the same set of quantum numbers within the same system; therefore, there is room for only two electrons in each spatial orbital. One of these electrons must have, \[m_{s}=\frac{1}{2}\] and the other must have \[m_{s}=-\frac{1}{2}\]. The orbitals of the subshell are each occupied singly with electrons of parallel spin before double occupation occurs. Accurate quantum-mechanical calculations have shown that the reason is that the electrons in singly occupied orbitals are less effectively screened or shielded from the nucleus, so that such orbitals contract and electron-nucleus attraction energy becomes greater in magnitude.
The below shows the spin states of Nitrogen: