The oxidation number of an atom is defined as the charge that an atom appears to have on forming ionic bonds with other heteroatoms. An atom having higher electronegativity (even if it forms a covalent bond) is given a negative oxidation state.
Oxidation number of N in NH3
Let x be the oxidation state of nitrogen in ammonia. The oxidation state of hydrogen is +1.
x + 3(+1) = 0
x + 3 = 0
x = −3
Here the oxidation number of Nitrogen is -3 and that of Hydrogen is +1