Water heaters are not really all that mysterious. A water heater heats water on a continual basis, whether you are using hot water or not. When you draw off hot water, cold water enters the tank to replace the hot water drawn out. When the thermostat senses the water temperature has dropped below the hold level, it initiates the heating element(s) in an electric water heater or the burner in a gas model. Even if you don't use hot water, the temperature in the tank will fall and so the water will be periodically reheated to bring it back up to the desired temperature. Because of this wasted energy, it is advisable to turn down the thermostat when away for extended periods of time, such as when you are on vacation.
Which Water Heater is Better: Gas or Electric?
Gas and electric water heaters are about equally common. An advantage of electric is that they don't require venting of the combustion gases as in a gas model. However, electric heaters may be more expensive to operate and generally don't heat cold water as quickly as gas models can. However, your choice may be dictated by what type of unit you are replacing. Often, changing from one energy source to another can be prohibitively expensive.
Detailed Explanation of Water Heater Operation
The cold water supply line connects to the water heater, typically on top of the appliance. Instead of dumping the water on top of the hot water in the tank, a dip tube carries the cold water down to the bottom of the tank. The outbound hot water line takes the water off the top of the tank. That way, when hot water is drawn out, it is at full temperature. Only after most of the hot water has been used do you start to get the hot and cold water mix.
When you open a hot water tap, the water pressure from the cold water supply line pushes the water out of the water heater and refills the tank with cold water. As cold water enters the tank, the thermostat(s) senses the lower temperature and triggers the heating mechanism.