Don't go out and buy a new one just yet. Many problems plague modern water heaters such as water quality to bad heating elements and thermostats. Since issues with gas water heaters are usually not a task that the average home owner should try to tackle alone, I will mainly address the issues with electric water heaters.
When I first approach a water heater in a home I determine which type of unit it is; gas or electric. Then I check the heat source. For gas units I check the size of the burner in relation to the capacity of the unit, as this can determine how quickly the unit will recharge its hot water supply. For electric units I check the resistance of both elements to see if they're working properly (not standard in most home inspections), as this is a common reason for reduced performance.
Prior to doing anything, shut off the supply power to the water heater at the service panel. By removing the covers from the water heater you can easily access the elements and the thermostats. If the resistance of one element is significantly lower (usually around 1 to 0 ohms) it is most likely shot. The average resistance is between 10 and 13 ohms. Replacing the element is relatively simple, but one should refer to the owners manual on exactly how to do it, not this blog.
Another issue that can cause issues resulting in the elements and/or the thermostat failing is the overall water quality. In a gas powered water heater there is a sacrificial anode rod which acts as a kind of magnet for impurities to attack rather than the sides of the tank itself. Gas powered water heaters lack this protection and sometimes rely on a protective layer of plastic on the inside of the tank itself. Instead of attacking the anode rod, impurities will be attracted to the elements themselves. When this happens heat can build up unevenly on the element causing it to fail.
Typically the upper element is the first to fail in an electric system. But sometimes the water contains enough impurities that they settle to the bottom of the tank over time. This causes a "mud bed" to form on the bottom of the tank. If the mud bed becomes too thick it can actually interfere with the lower element by causing heat buildup eventually causing lower element failure. Removing this mud is relatively simple but will require some work. Most plumbers offer this service.
Finally, if the elements have been malfunctioning for a long time the thermostat has most likely failed as well. First, ensure that the reset button has not tripped as this is a common problem. Nuisance tripping could be a sign of either a bad thermostat or a bad element. Next, check the resistance of the thermostat itself (refer to manual). Bad resistance numbers = bad thermostat.
There are many online resources that will guide you on how to conduct most of these problems, just be sure that you are being safe while doing them. And when in doubt ask for help from a licensed plumber.