A thermostat is a switch that reads temperature and calls for heat. When it fails, the tank either stops heating, heats to the wrong temperature, or cycles unpredictably. The part is inexpensive; confirming that it is the part is the work.
Electric: two thermostats, one sequence
A conventional electric tank has an upper thermostat and a lower thermostat, one for each element. The upper one also decides which element runs: it heats the top of the tank first, then hands over to the lower element.
That sequence explains the symptoms. An upper thermostat that fails open leaves the whole tank cold. A lower thermostat that fails leaves the top hot and the supply short. Testing at the terminals, with power isolated, identifies which one has failed.
Gas: the thermostat is inside the valve
On a gas heater, the temperature control is part of the gas control valve rather than a separate replaceable thermostat. A gas unit that will not hold temperature is diagnosed as a valve or control problem, and the repair is a gas-valve replacement — a different job with a different part.
The temperature question
The Department of Energy's guidance puts most households at about 120°F. That setting slows mineral buildup in a hard-water city and reduces the scald risk at the tap. A dishwasher without a booster heater may require 130–140°F, and a household with immunocompromised occupants may consider 140°F with mixing valves at bathing fixtures.
The setting is a household decision, but the dial is not a thermometer. Measuring the water at the farthest tap is how the actual temperature is confirmed.
Swapping the part
With the breaker off and the cover removed, the control is tested across a heating cycle rather than replaced on suspicion. If it has failed, the substitute has to match the model and the element it switches, which means the unit's rating plate rather than a part that looks similar. The tank is then refilled and the air worked out of it before the breaker goes back, since an element that comes on dry is destroyed in seconds.
Reading the tap instead
Symptoms overlap more than the labels suggest. Hot upstairs and cold at the far end of a hillside run can be a thermocline rather than a fault, and lukewarm everywhere can be storage, sediment or a long pipe losing heat on its way to a distant bathroom. Measuring at the fixtures before touching the control is what separates a part failure from a volume or recovery problem. Testing the thermostat is the start of the diagnosis, not the whole of it.