Or, you can break it into different half-reactions which will show where the electrons go. For example, here's the first equation broken up:
1) Mg(s) -> Mg
+2(aq) + 2e
-. The solid magnesium has no charge, but the aqueous Mg has a charge of +2. To balance that, you need two electrons.
2Cl
-(aq) -> 2Cl
-(aq). On the right side you have two chloride ions, so to balance the charge and atoms, you need to add another chloride ion on the left.
2H
+(aq) + 2e
- -> H
2(g) The hydrogen on the right side contains zero charge, yet the hydrogen on the left has a charge of +1. To balance it, you need two hydrogen atoms and two electrons. Now both sides have the same number of atoms and the same number of electrons. Now you just need to add all three equations.
Mg(s) + 2Cl
-(aq) + 2H
+(aq) + 2e
- -> Mg
+2(aq) + 2Cl
-(aq) + H
2(g) + 2e
-Now removing whatever's the same on both sides, you get: Mg(s) + 2H
+(aq) -> Mg
+2(aq) + H
2(g)
This could also be written as Mg(s) + 2HCl(aq) -> MgCl
2(aq) + H
2(g)