Magnesium has a positive 2 charge and nitrogen has a negative 3 charge. To completely balance it out, you need three magnesium’s and two nitrogen’s. The final charge for magnesium would be positive 6 and the final charge for nitrogen would be negative 6, this will make it neutral.
When baking powder is added to a cake, the acid base reaction it undergoes with the acidic butter produces the carbon dioxide that makes the cake rise.