#"Oxidation number"# is the charge left on the central atom, when all the bonding pairs of electrons are broken, with the charge assigned to the most electronegative atom.
Thus when we (conceptually!) break the bonds of water, #H_2O#, we get #2xxH^+# and #O^(2-)#. Oxygen is more electronegative than hydrogen, and thus it gets the 2 electrons from the #H-O# bonds.
But if we do this for a peroxide linkage, #HO-OH#, clearly each oxygen atom has the SAME electronegativity, and when the bond is broken, we assume that the 2 electrons that form the bond, are equally shared by each oxygen atom:
#HO-OHrarr2xxHO*#, and thus when we break the remaining #H-O*# bond we get #H^(+)# and #O^(-)#. Accordingly, oxygen in peroxide has a formal oxidation state of #-I#.
To continue this theme of oxygen oxidation states, what is the the oxidation number of oxygen in the real molecule, #OF_2#. Remember the definition of oxidation state.
Also see this old answer.