There are 6 hydrogen atoms on the reactant side while only 2 hydrogen atoms on the product side. To balance the hydrogen atoms, 3 should be written as a co-efficient of the hydrogen atoms present on the product side. To balance the equation, place whole numbers ahead of the formulas so as to have the same number of all elements on each side.
Mg + 2HCl → MgCl2 + H2