In a water molecule, oxygen pulls the shared electrons of each O–H bond closer to itself, because oxygen is more electronegative than hydrogen. Oxidation numbers turn this into a bookkeeping rule: pretend the more electronegative atom takes the shared electrons completely. Oxygen, credited with two extra electrons, is −2; each hydrogen, having lost its electron, is +1. The numbers add to zero, matching the neutral molecule: 2(+1)+(−2)=0.
That sum rule is how you find unknowns. In sulfuric acid, H2SO4, hydrogen is +1 and oxygen −2, so 2(+1)+S+4(−2)=0 and sulfur is +6. In the sulfate ion, SO42−, the sum must equal the ion's charge: S+4(−2)=−2, so sulfur is again +6. One element can take many values: sulfur is −2 in H2S, +4 in SO2 and +6 in SO3. The more oxygen around it, the more electrons it has given away on paper.
An oxidation number is not always a real charge. In methane, CH4, carbon is −4, yet methane is a neutral molecule with no ions at all; −4 is just the count you get by handing carbon all the shared electrons. Only for simple ions, such as Na+ in sodium chloride, do the oxidation number and the actual charge agree. The rules also have exceptions: oxygen is −1 in peroxides such as H2O2, and hydrogen is −1 in metal hydrides such as NaH.
Think of it like this. Oxidation numbers are like a strict referee scoring a tug-of-war over every shared electron pair: the stronger puller, the more electronegative atom, is credited with both electrons even if the real contest was close. The scores always add up to the overall charge. Real molecules share more fairly than the scoreboard says.
Core idea. Treat every bond as if the more electronegative atom took all the shared electrons. The resulting charges, which must add up to the overall charge, track where electrons move during a reaction.