If hot water runs out fast when it used to last, something changed inside the heater. If it has never lasted, the heater is too small for the house.
1. Sediment in the tank
Minerals settle on the bottom and take up space that should hold hot water. You may also hear the water heater making noise. Flushing helps.
2. A broken dip tube
The dip tube sends incoming cold water to the bottom of the tank. When it cracks, cold water mixes straight into the hot water leaving the top. The telltale sign is lukewarm water after only a minute or two.
3. A failed lower element (electric)
Electric tanks have two elements. If the lower one fails, only the top third of the tank heats.
4. A thermostat set too low or failing
Check the setting first. 120 degrees is the usual recommendation.
5. A crossover
A failed mixing valve or single-handle faucet cartridge can let cold water bleed into the hot line.
6. The tank is too small
More people, a bigger tub or a new shower system can outrun a 40 gallon tank.
Fixes
Items 1 to 5 are a water heater repair. For an aging or undersized tank, look at water heater replacement with a larger unit, or tankless water heater installation for hot water that does not run out. If there is no hot water at all, call for same-day service.
Common questions
How long should a 50 gallon water heater last in the shower?
Roughly 20 to 30 minutes of continuous showering with a standard shower head, less with high-flow heads.
Does a tankless heater ever run out?
No, provided it is sized for the number of fixtures in use at once.