The hardness of hard water is due to the presence of chlorides and sulphates of calcium and magnesium. When washing soda (Na2CO3. 10H2O) is added to the hard water, Na2CO3 reacts with the chlorides and sulphates of calcium and magnesium and converts them to insoluble carbonate salts. This changes the hard water into soft water and thus makes it suitable for use.
MgCl2 (aq)+ Na2CO3 (s) - MgCO3(s) + 2 NaCl (s)