what is the reason hydrogen have -1 oxidation number?

Hydrogen usually has an oxidation number of +1 when combined with nonmetals such as Cl (HCL), S (H2S), etc. However in metal hydrides such as NaH, CaH2, etc, its oxidation number is -1 since its electronegativity is lower than that of the element it is combined with.