The battery in your car is a plastic box, filled with metal, chemicals, and electricity. Without going too deeply into the details, a chemical reaction occurs to create electricity, which flows out of the terminals to turn the starter and run the electronics, until the engine can generate its own power.
Because it is a chemical reaction, it is effected by the ambient temperature, and it can be contaminated and made ineffective by the environment it is in. As the alternator is turned by the engine, it charges the battery by reversing the chemical reaction, but it is not perfect. With time, heat, vibration, and the charge discharge cycle eventually render a battery no longer able to hold a charge, or otherwise bad.
In normal use, a car's battery ought to last more than 5 years. But since they fail quickly once they start to go, here are some warning signs.
Warning Lights on Dash
Has the little battery shaped red light appeared on your dash? This doesn’t always mean the battery is it fault, but it does mean something in the charging system is out of sorts. It could mean the battery was undercharging, or overcharging, and it could be another alternator, voltage regulator, or battery issue, or just a loose or broken connection somewhere.
The computer systems monitoring cars in the 21st-century are much more sophisticated, and handle voltage regulation as well. They will light the warning light for a battery being discharged, but they may set a diagnostic code as well.
If the light does come on, you typically only have a few miles of driving until the motor stops, even less if your headlights or wipers are on. Get home, or to your nearest repair shop or auto parts store as soon as possible. Chances are if you shut the car off it isn't going to restart.
Slow Cranking in Hot or Cold
One of the first warnings that your battery is on its way out is how it performs when the weather turns hot or cold. In cold weather, the chemical reaction doesn't produce quite as much power, and on top of that the engine is harder to crank over, so a marginal battery may not be able to turn the starter at all. Hot weather stresses the battery as well, and you may find it hard to start the car after shutting it down when it is hot, while running errands for instance.
If your vehicle doesn't start normally in the heat or cold, that first suspect part should be the battery, because batteries are expendable. Alternators and starters these days will last the length of the powertrain warranty (10 years or 100,000 miles) but batteries seldom last more than five.
Slow Cranking After Sitting
If you live somewhere with a moderate temperature all year, it may never be cold enough to affect the cranking power. But another way batteries fail is one cell at a time, and with a "bad cell" you will notice the car is slow to start after sitting over night, or while you are at work.
The typical battery consists of six "cells", in a common acid bath. If one of the six cells won't hold an electrical charge, your battery may only put out 10 volts, instead of 12 volts, and 17% less amperage when you try to start it after sitting for a few hours. Depending on the car, this may be enough to get going, but the cranking will be noticeably slower. It is only a matter of weeks before it gets worse and won't start the car at all, so plan on getting a battery next pay day.
Your battery could be perfectly fine internally, but if the terminals or the cable ends are covered in corrosion and oxidation, or just have a hard time clamping, the battery’s power is a moot point. Your terminals need to be tight, clean and free from grease, dirt or any other detritus in order to provide full amperage from the battery to the starter.
It isn't really part of the battery, but if you have a slow cranking or no start condition, you may have a battery cable which has internal corrosion. The resistance from one end to the other should be very low, a fraction of an ohm, when tested with a multi-meter. Or if testing the voltage, it should only be about .3 volts less when tested at the far end of the cable, compared to the battery end.
Inspect the Box
As mentioned, a battery is a plastic box, holding some pretty nasty stuff inside of it. The plastic should outlast the stuff inside, but it can crack due to impact, or due to exposure to extreme heat, or freezing. Inspect the exterior of the battery for cracks, wet spots, or bulges with a light.
Make sure the caps on top of the battery are intact, and on tightly as well. Modern batteries are "sealed" and don't need to be topped up with distilled water like they did 40 years ago. But they can still expel gasses, and it is still possible for the electrolyte to to become contaminated. It doesn't take much in the way of a contamination to kill a battery completely.
One of the best ways to test the battery and the rest of the charging system is to use a multimeter. A good battery should measure at more than 12.5 volts between the terminals.
You can also use the multimeter to determine if the battery holds a change, by testing it and testing it again an hour later. A good battery should have almost no difference, even if tested after an overnight rest.
There are other ways to use a multimeter to test your charging system. You can read about them in detail here: How To Test a Car Battery With a Multimeter