Water softeners are exchange systems, in that they exchange ions in the water. Calcium (Ca2+) and Magnesium (Mg2+) are the ions that cause hardness in water. Sodium (Na+) is the ion that a water softener uses to replace the calcium and magnesium ions with, resulting in soft water.
Resin inside the water softener is used as an exchange medium. The resin loosely holds the Sodium (Na+) ions which are exchanged with Calcium (Ca2+) and Magnesium (Mg2+) ions. Once the resin becomes coated with the calcium and magnesium ions, it must be regenerated and flushed out. The resin can now remove Calcium and Magnesium again..