Firstly there are two rules that you should know
(1) oxidation of an element = 0
(2) the O number of a monoatomic (one atom) ion is the same as charge on the ion
Now... take H2SO4
let oxidation state of S be X (there is only 1 X)
Oxidation state of (Hydrogen) H2 =+2 AND (oxygen) O= -2 (But there are in fact 4 O.... so it will become (- 2)*(4) = -8
so (+2) + (X) + (-8) =0 .................... X = +6
hope it was helpful :)