What is the shutdown order, exactly?
Water first, then energy. Close the cold inlet valve at the top of the unit, then switch off the gas control and its supply valve, or the breaker on an electric unit. Then deal with the floor.
Water first because that is what stops the loss growing. Energy second because an element or a burner working on an empty or emptying tank damages the appliance and is a hazard in its own right. Doing it in that order takes about a minute and needs no tools.
Both valves are worth finding before anything goes wrong. The cold inlet valve is on the pipe entering the top of the unit; the gas supply valve is on the line feeding it; the breaker is labeled in the panel, or should be. A household that knows those three locations loses a tank of water rather than a basement.
Why is the cleanup bigger than the appliance?
Because the water goes where the building lets it, not where the unit is. A basement floor spreads it across the slab and into wall bases, stored contents soak it up, and a unit above finished space sends it through the ceiling below.
The appliance is replaced in a morning by a plumber. The building takes longer, because the water has been absorbed by the slab, the base of any finished wall, whatever insulation it reached and whatever was standing on the floor. Cardboard, upholstery and chipboard furniture are usually unsalvageable after a few hours in standing water.
This is why the first conversation is about the wet area rather than the heater. A measured boundary tells you which contents need moving, whether a finished wall has to be opened at its base, and how much equipment the drying needs. It also gives the household an inventory for an insurer, which is otherwise reconstructed from memory.
Can a wet heater be put back in service?
Not without a check. A gas unit whose controls or burner have been under water, and an electric unit whose elements or thermostats have been wet, both stay off until a qualified person has looked at them.
The parts that get damaged are the ones that are hardest to see: a gas control, a thermocouple, a thermostat, the insulation inside the casing. A unit that appears to work after a soaking can be unsafe, and a flue or a vent that has been disturbed is its own hazard.
The same applies to anything else in the room that was submerged: a furnace or boiler, a pump, a freezer. It is also worth asking whether the heater is the age at which this failure is expected. Replacing a tank that is already old while the floor is open is cheaper than replacing it twice.
What goes into the cost?
How long it ran, the area the water covered, whether finished walls or a ceiling below are involved, the contents affected, and the drying time a basement needs. The appliance replacement is separate and is a plumber's work.
A tank that failed with somebody at home, onto a bare basement floor, is at the small end. The same failure running for a day or two, into a finished lower level with carpet, board and stored possessions, is a different job with removal, disposal and reinstatement in it.
Basements also dry slowly, which costs equipment days rather than labor hours: concrete holds a great deal of water and sits at the temperature of the ground. No figures appear anywhere on this site, and a scope and a price are agreed before the work rather than presented afterwards.
How is the next one avoided?
Know the age of the unit, look at its base occasionally, have the anode rod and the relief valve checked, and fit a pan and a water sensor where a failure would be expensive.
Tanks give notice, and the notice is at floor level: rust at the base, a mark that keeps returning, discolored hot water, a change in how long the hot water lasts. A two-minute look during a cold spell or at the start of a season catches most of it, and a plumber's check of the anode rod and the relief valve extends the life of the unit.
Where the unit stands above finished space or beside anything valuable, the hardware is cheap against the alternative: a drain pan plumbed to a drain, a sensor that closes the supply when it detects water, and nothing stored directly on the floor around it. And when the unit is replaced, that is the moment to choose a position where a future failure drains somewhere harmless.