The hardness of water, caused by mineral deposits like calcium and magnesium, can affect water heaters by causing scale buildup on heating elements or inside the tank. This buildup reduces efficiency, increases energy consumption, and shortens the lifespan of the heater. Regular maintenance, such as flushing the tank or using a water softener, can mitigate these effects and prolong the heater's lifespan.