The main purpose of a car battery is to change chemical energy into electrical energy when the engine starts. The battery also helps power accessories like the clock, radio, and alarm systems. Car batteries are designed to recharge as the car runs, but if the battery is not used regularly it can drain down and become dead. Leaving the keys in the ignition will quickly deplete a battery and leave you without a car, just ask Ferris Bueller or Jesse Pinkman.
Basically, a car battery is a series of lead plates submerged in an electrolyte solution of sulfuric acid. The plates create a positive and negative circuit when they are charged, allowing electrons to pass between the two sides. When you turn on the ignition, it sends a signal to the alternator that charges the battery with electricity.
The battery still powers electrical parts of the vehicle after the engine is running, including the lights, navigation system, and audio systems. If you leave your car in storage with the key in the ignition, these systems continue to draw on the battery for power, causing it to drain faster.
Keeping your car in storage for long periods of time can cause the battery to develop a hard crust, called sulfation, which will stop it from accepting a charge. You should store your battery in a cool, dry place, such as inside a garage or shed. Keep it covered to avoid exposing it to sunlight or water which can damage the internal components of the battery.