The law of conservation of mass says that no mass is lost or gained in a chemical reaction. The total mass of the reactants is always equal to the total mass of the products. This holds when nothing can enter or leave the reaction vessel, such as in a sealed flask.
The reason is that atoms are not created or destroyed in a reaction. They are rearranged into new substances. Every atom that was in the reactants is still there in the products, so the total mass stays the same and is conserved. A balanced equation shows this, because it has the same number of atoms of each element on both sides. In 2Mg + O2 → 2MgO there are 2 magnesium atoms and 2 oxygen atoms on each side.
The law lets you calculate an unknown mass. If 6.0 g of magnesium reacts completely with 4.0 g of oxygen, the mass of magnesium oxide formed is 6.0 + 4.0 = 10.0 g. If 2.4 g of carbon reacts completely with 6.4 g of oxygen, the mass of carbon dioxide formed is 8.8 g. Working backwards, if 10.0 g of magnesium oxide forms from 6.0 g of magnesium, the oxygen that reacted must have had a mass of 4.0 g.