
Oxidation number of elements is usually the number of electrons it can donate (positive oxidation number) or take up (negative oxidation number) to complete its octet. This depends on the number of electrons present in the outermost shell of the atom of this element.
For example, N has 5 electrons in its outermost shell, so to complete its octet it needs only 3 more electrons. So its oxidation number is 3-.
Another example of sodium, Na. Na has 1 electron in its outermost shell. So it can easily lose this electron and achieve its octet. Thus oxidation number of sodium is 1+.