Sodium is a good reducing agent (i.e. liberates electron) and therefore displaces hydrogen from water.
The reaction can be explained as under:
2Na0 +2H2+1O-2→2Na+1O-2H+1+H20
We can see sodium is oxidized to +1 oxidation state and hydrogen is reduced to 0 oxidation state.
This is a redox reaction (reaction involving oxidation and reduction simultaneously )in which sodium gives electrons and these are accepted by hydrogen ions to form hydrogen gas.
2Na→2Na+ +2e- (oxidation)
2H+ +2e- →2H (reduction)
H+H→H2