A water heater is bad if, after a few troubleshooting checks, it does not heat water anymore. Residential water heaters usually have to be replaced due to age or significant hard water build-up.
A water heater needs to be replaced if it costs more to fix than it does to buy a new one. Most newer water heaters have better insulation and provide more energy efficiency, so that is another factor to consider when deciding if a replacement is needed.
If no hot water is being produced, the pilot light must be checked to see if it is lit. Gas water heaters have a pilot light that needs to be burning. If the pilot light is not lit, it must be relit
For water that is not hot enough, the thermostat needs to be checked. If it is set correctly, mineral build-up is the possible culprit. In areas where water is "hard" or contains a lot of minerals, lime deposits line the water heater. Over time, the build-up of these deposits can affect the amount of hot water the tank holds and the ability to warm it sufficiently. It is wise to drain the water heater periodically to remove the deposits.
Other problems include leaky valves. Water on the floor around a water heater means a valve is leaking and needs to be replaced. Sometimes the cost or hassle of draining or replacing valves is more than buying a new water heater, especially if a water heater is more than a decade old. That is when replacement of the water heater needs to be considered.