Caused by magnesium and/or calcium ions from rocks.
Magnesium and calcium sulfate dissolve in water. MgSO4 and CaSO4. This creates permanent hardness.
Calcium carbonate dissolves in acid rain to form calcium hydrogencarbonate, Ca(HCO3)2, which is soluble. This creates temporary hardness.
Temporary hardness can be solved by boiling; the calcium hydrogencarbonate decomposes to for insoluble calcium carbonate.
Ca(HCO3)2 > CaCO3 + H2O + CO2
Both types of hardness can be solved by ion exchange. The water is fed through an ion exchange resin that exchanges sodium or hydrogen ions for the calcium or magnesium ions.
Na2Resin + Ca > CaResin + 2Na
A resin is a solid polymer that's insoluble in water