A balanced equation shows the ratio in which substances react. Using relative formula masses, you can turn that ratio into masses and then scale it to the mass you are given.
Example: 2Mg + O2 → 2MgO. The reacting masses are 2 × 24 = 48 g of magnesium, and 2 × 40 = 80 g of magnesium oxide. This means 48 g of magnesium makes 80 g of magnesium oxide. To find the mass made from 12 g of magnesium, divide the given mass by the reacting mass to get a scale factor: 12 ÷ 48 = 0.25. Then multiply the other reacting mass by it: 0.25 × 80 = 20 g of magnesium oxide.
It works backwards too. To make 40 g of magnesium oxide, the scale factor is 40 ÷ 80 = 0.5, so the mass of magnesium needed is 0.5 × 48 = 24 g.
Example with two products: CaCO3 → CaO + CO2. The relative formula masses are 100, 56 and 44. Heating 25 g of calcium carbonate gives a scale factor of 25 ÷ 100 = 0.25, so it makes 14 g of calcium oxide and 11 g of carbon dioxide. The two products add up to 25 g, the mass you started with.