Water heaters work by heating water in a tank or through a heating element to provide hot water for various household needs.