The balance equation for the combustion of magnesium (combination/synthesis reaction) is:
2Mg + O2 = 2MgO
The idea behind balancing equations is Conservation of Matter. Matter can not be created nor destroyed so during a reaction the number of atoms of each element must be conserved.
If you start with one magnesium and two oxygens on the reactant side of the equation, then you need to make sure that you have at least that same number on the product side of the reaction. In order to have 2 oxygens on the product side, you have to place a 2 in front of the MgO. By doing this, you created 2 magnesiums. To correct and balance this, you place a 2 in front of the magnesium on the reactant side and then you end up with 2 magnesiums and 2 oxygens on both sides of the equation.
When I teach my students how to balance these types of reactions I tell them about my odd-even rule. It goes like this, If you have an odd number of an element (in this case oxygen) on one side of the equation, and and even number of that same element on the other, If you place a "2" in front of the very first element or compound (in this case Mg), you will then balance the entire equation more easily.
Lastly, remember that you can only add coefficients (numbers out front) to balance reactions. You can NOT change subscripts (numbers written below a chemical symbol) like the 2 in O2. Also, you can NOT split compounds and put numbers in between elements like Mg2O.