Oxygen always has an oxidation number of -2 and
Hydrogen always has an oxidation number of +1.
Many other elements have more than one oxidation number.
Example 1: SO2
In SO2, there are 2 oxygen and each oxygen has a -2 charge.
2 x -2 = -4. Oxygen contributes a -4 charge to the molecule.
The molecule is neutral, so S has to have a charge that balances out oxygen's -4.
S + -4 = 0
Sulfur's charge is +4.
Example 2: (SO4)2-
In (SO4)2- there are 4 oxygen and each oxygen a -2 charge.
4 x -2 = -8. Oxygen conrtributes a -8 charge to the polyatomic ion.
Overall the polyatomic ion has a -2 charge.
Sulfur's charge plus oxygen's charge must equal -2.
S + -8 = -2
Sulfur's charge is +6.