By means of first-principles calculations, we have proposed an ab initio modeling to establish a formula between the hydrogen evolution rate and its overpotential of hydrogen evolution reaction (HER), relating with three different rate determining mechanisms, when Volmer reaction, Tafel reaction and Heyrowsky reaction are the rate determining steps of the entire reaction, respectively. Within this modeling, the free energy (ΔGH*) of the adsorbed hydrogen atom and the concentration of hydrogen ions in the solution have been correlated to the exchange current density. The hydrogen evolution modeling has been validated by available experimental results. Furthermore, by combining the previously proposed first-principles modeling of the anodic dissolution and this modeling of the HER in the electrochemical corrosion, the polarization curves of the 18 crystallographic surfaces of pure Mg have been theoretically derived. It has been found that in a neutral solution (pH=7) the corrosion current densities (icorr) of the 18 crystallographic surfaces range from 10−3.477 to 10−0.455 A/cm2 and their corresponding corrosion potentials (Ecorr) range from −1.36 to −0.892 VSHE, respectively. The base (0001) surface exhibits a lower corrosion rate of 10−3.345 A/cm2, whereas the crystal (213¯0) surface has a fast corrosion rate of 10−0.455A/cm2. The calculations even reveal that except for Ag, all the other alloying elements considered here accelerate the rates of the cathodic HER. In agreement with theoretical results, the experimentally measured polarization curves of the Mg-1Zn and Mg-2Sn alloys verify that both Zn and Sn additions accelerate the rate of the HER of Mg.