Does a water heater consume more energy if constantly kept on than if it is made to heat the water on demand? Suppose I have a water heater, an insulated tank of water that when turned on heats water to a predefined higher than ambient temperature and keeps it at that temperature.
Suppose I don't need the water to be hot for an amount of time. How can I determine if it is more economic (i.e. consuming less energy) to turn off the heater or keep it on based on the amount of time?
My instinct says that it is always a good idea to turn the heater off no matter the amount of time it will be needed again. Let me explain.
The initial and terminal state of the whole system is identical in both scenarios: the water is hot. Therefore the amount of energy input must be equal to the amount of the energy lost (dissipated from the heater). The heat flow can be calculated via Newton's cooling law:
$$\frac{\text{d}Q}{\text{d}t}=-uA\Delta T$$
Which is to say the heat loss is proportional to the temperature difference. If the heater is kept on, the heat flow will stay constant but if the heater is turned off the water temperature will drop and consequently the rate of energy loss will drop as well. This leads me to believe that over any amount of time the heater will lose (and therefore consume) less energy if turned off even if it temporarily consumes more power during the re-heating phase.
Am I making a mistake somewhere in my reasoning or am I correct? Are there other factors that I haven't taken into consideration that make it impractical to turn off a heater when not in use?
 A: Yes, your reasoning is correct.
Let's consider a cylinder:

*

*Diameter 0.5m

*Length 0.8m

*Internal volume 157l

It has a total area of $ 1.65 m^2 $.
Suppose it is insulated with PIR foam, thickness 5cm, thermal conductivity $ \lambda = 0.022 W/m.K $.
The thermal conductivity between interior and exterior of this cylinder will be 0.036 W/K.
So if the inside contains 60°C water, and the outside is 25°C air, we have a delta T of 35K, so it will lose 1.27W thermal power to the environment, which needs to be supplied by the heater.
That's theory. In practice, insulation costs money, and money is expensive. In addition, there are two metal pipes bridging the insulation, and the part with the thermostat is insulated. So you can expect it to consume about 40-60W just to keep temperature steady. This also includes the drip, see below.
There's also the expansion of water. The steel enclosure linear expansion coefficient of about $ 10^-5 $ in all dimensions, so the internal volume won't change much, but 60°C water has a $ 5.10^-4 $ volumetric coefficient of expansion.
So, when it heats by 1°C, the safety valve will expel 75ml of water. If you just took a shower, that will be cold water, but if it has been idling for a while and has heated all the way to the bottom, then it will be warm water. So how much that will cost will change a lot depending on circulstances.
Anyway. The reason to keep it hot continuously is to avoid legionella bacteria, which may develop in water below 55°C. Then you take a shower, breathe some of it in, and get pneumonia. People who use solar heaters implement a full heating cycle to 65°C to kill the bacteria, but only once a week.
