Oxidation states are hypothetical charges we assign by assuming the bonds are completely ionic, i.e. complete transfer of valence electrons to the more electronegative atom. Really, the core hierarchy is:
Charge is conserved, so that all the oxidation states in a neutral substance add up to 0, or in an ion, add up to its charge.
Pure elements have an overall oxidation state of 0 (follows from (1)).
Oxidation states are predicted by the typical charge obtained with a noble gas electron configuration.
The more electronegative atom is given the negative oxidation state and vice versa. This one is especially important for non-obvious cases when we have to designate uncommon oxidation states to an atom that won't follow typical valencies.
In a bond between two identical atoms, they have the same oxidation state, whatever it may be. This rule is governed by (1).