The law of conservation of mass says that no atoms are made or destroyed in a chemical reaction. Atoms are rearranged into new substances, so the total mass of the reactants equals the total mass of the products.
In a closed system, nothing can enter or leave the container. A precipitation reaction in a closed flask is an example. If silver nitrate solution and sodium chloride solution are mixed in a sealed flask, a solid white precipitate of silver chloride forms. The flask and its contents have the same mass before and after, because nothing has escaped.
In a non-enclosed system, such as an open flask, gases can enter or leave, so the mass can appear to change. If marble chips react with acid in an open flask, carbon dioxide gas escapes into the air and the mass shown on the balance decreases. If magnesium burns in air, it takes in oxygen from the air, so the mass of the solid increases. The mass of magnesium plus the mass of oxygen that reacted equals the mass of magnesium oxide formed. No mass has been lost or gained overall. The gas has simply been missed.