The oxidation state of hydrogen is $+1$ in all of its compounds (except in metallic hydride)
The oxidation state of $Na$ and $Mg$ is $+1$ and $+2$ respectively while the oxidation state of oxygen is $- 2$ (except peroxides and $OF_{2}$ ).
The oxidation state of $N$ in $NH_{3}$ is
$x + 3(+1) = 0$
$x = − 3$
The oxidation state of $N$ in $HNO_{3}$ is
$1 + x + 3(− 2) = 0$
$x = 5$
The oxidation state of $N$ in $NaN_{3}$ is
$+ 1 + 3x = 0$
$x=-1/3$
The oxidation state of $N$ in $Mg_{3}N_{2}$ is
$3(2) + 2x = 0$
$6+2x=0$
$2x = − 6$
$x = − 3$
Hence, three molecules (ie, $NH_{3}, NaN_{3}, Mg_{3}N_{2})$
have negative oxidation state