Deciding it is over
The hardest part of replacement is usually accepting it. A heater that has been repaired three times in two years, rumbles through every recovery and leaves the last shower cold is telling you something, even if it never quite fails outright.
The clear signal is water from the tank itself. A leaking drain valve, a passing relief valve or a loose nipple can all be fixed. A shell that has split, or a base rusted thin enough that water weeps through the steel, cannot. Once that is the case, every further repair is money against a countdown.
The less obvious case is scale. On hard water, sediment layers on the burner plate until the tank holds less hot water and takes longer to make it. A unit like that can be technically working and still useless for the household, and flushing only recovers so much once the layer has set.
What replacement actually involves
Drain the old unit, disconnect the gas or electrical supply, cut it free of the plumbing and get it out — which on a closet install can be most of the physical work. Then the new unit goes in with its pan and drain, relief valve and discharge, seismic strapping, venting to the manufacturer's specification and supply connections checked against its requirements.
On the same footprint, that is a single visit for most storage tanks. When the new unit is a different size, a different fuel, or a tankless conversion, the venting and supply work grows, and it is planned as such.
Sizing the replacement honestly
The easy answer is the same gallonage again. The better answer asks who lives there, how many bathrooms run at once, whether laundry happens in the morning, and how the hot water ran out before the old unit failed. Sometimes the old unit was undersized from the day it went in, and the replacement is the one chance to fix that.
What not to do
Do not cap a leaking tank's relief valve, do not run a gas unit with the burner area wet, and do not leave a failing tank in a closet above finished floor space while you decide. Shut the cold inlet and the fuel off, drain what you can, and ring.
Related reading
Repair or replace your water heater? How to decide weighs a part failure against a failed shell, and explains why age alone does not settle it.