A tank water heater of more than about 20 gallons has two thermostats, and two heat elements. If you begin with a full tank of hot water, both thermostats are satisfied and both heat elements are OFF. As you use hot water, you are drawing from the top of the tank (heat rises remember) and the cold water enters and travels down the "dip tube", most of which nowdays, have a curve at the bottom end of them. This curve creates turbulence and keeps sediment from accumulating on the bottom. The cold water that enters stays on the bottom (cold water is heavier and settles, so it stays on the bottom), creating a huge stratification of temperature in the tank). When the bottom of the tank gets cold enough, as more and more cold water enters, the bottom thermostat turns ON the bottom heat element, to heat up that cold water.
If you stop drawing hot water at that point, the lower element will heat the water, and the thermostat will satisfy and the lower element will shut off, and the water heater will be "at rest" ready for the next use.
If you continue to draw hot water, the level of cold will rise in the tank and the lower element will not be able to keep up with it, soon the tank will be full of cold water, and when the top thermostat senses cold up high in the tank, it switches OFF the bottom element, and turns ON the top element, in a last ditch effort to provide you with some hot water.
If at this point you cease to draw hot water, the top element will continue to heat the top of the tank until the top thermostat is satisfied and it then switches OFF the top element and allows the lower thermostat to turn ON the lower element if it needs to (and it will, as the lower part of the tank is still cold) and the lower element will heat up the water until the tank is entirely hot, and the lower thermostat is satisfied, at which point the lower element is switched OFF and the heater is "at rest" again.
The two elements are NEVER on at the same time, as this would overload the circuit.
Charles