Make sure the battery needs replacing. You don't want to spend time and money installing a new battery if the problem is not with the battery itself. Look for sulfate build-up in the form of a whitish or blue residue around the terminal--removing this can sometimes solve issues with a faulty battery. DO NOT TOUCH THIS POWDER WITH YOUR BARE HANDS, as it can often contain dried out sulfuric acid which will begin to unnoticably corrode your skin. Also verify that the battery has been given the chance to recharge properly by driving constantly for 30 minutes (with minimal electrical usage, including the air conditioner). Finally, check the alternator. Some cars also have a battery meter, with the engine running, the alternator usually maintains a charge close to 13.8-14.2 volts in a properly functioning charging system. The battery should have 12.4-12.8 volts with the engine off, and with no accessory load. If you've determined that your battery problems can't be attributed to any of the above, or if you see cracks or oozing liquid on the top of the battery, it's probably safe to proceed with replacement.
Buy the correct replacement battery. Find out what kind of battery you're replacing (Or the dimensions of your battery) and bring this information to a local auto parts store. This is important because automotive batteries vary in size, and you will want to purchase a battery which matches the size of the battery tray/support in your vehicle.
In some areas of the US, you will be charged a "core" fee when you purchase a new battery, if you bring in your old battery after or when purchasing your new battery you will not get charged this fee**
Set up a secure working environment - Park on a flat, level surface at a safe distance from traffic, sparks or open flames. Put on the parking brake. Don't smoke, and make sure any smokers in proximity to the working area know not to smoke as well. Remember that electricity is not the only danger; batteries contain a sulfuric acid electrolyte solution, which is highly corrosive (i.e. can burn your skin) and produces a flammable gas. Put on gloves and safety goggles.
Remove the cigarette lighter and plug the memory keeper into the lighter socket. A memory keeper will keep the PIN codes and settings for radios and navigation systems from getting erased when you disconnect the battery. If you don't have a memory keeper make sure you have all the PINs for your electronic equipment before you start. Use may wish to check your car manual to see what devices may be affected.
Open the hood - After opening your hood, use the prop rod to keep your hood open (Most newer cars have hoods that hold themselves up.
Locate the battery - The battery should be located in an accessible part on either side of the car's frame. The battery is a rectangular box with two cables attached to it. Some european cars (BMW's, new Benz-Chrystler's) have the battery under the metting in the trunk, or inside the fender of the wheel well (The latter is often very difficult to remove).
Identify battery terminals - Locate the positive and the negative terminals of the old car battery. The positive terminal will have a plus sign and the negative terminal will have a minus sign.
Disconnect the negative terminal - Loosen the negative cable clamp with a wrench (Usually 8mm or 10mm) and slide it off of the terminal. If the cables are unmarked, label them so that they don't get mixed up (otherwise you may ruin your car's electric system later on). It is also important that you disconnect the negative terminal socket before the positive terminal socket. Otherwise, you may short circuit the positive terminal to a grounded part of the car.
Disconnect the positive terminal.
Remove the car battery - Unfasten the battery holder and remove any screws, clamps or bars holding the battery in place. Carefully lift the battery out of the car. Remember that a battery can weigh 30 to 60 pounds, or 13.5 to 27 kilos, so if you have any back problems, get a helping hand.
Clean the terminal clamps and the battery tray. You can use a baking soda solution and a wire brush. If there's any severe corrosion, consider replacement by a mechanic. Otherwise, let the area dry before moving onto the next step.
Replace the battery - Place the new battery where you just took the old battery out, with the positive and negative terminals on the correct sides. Connect all the screws, clamps or bars that may hold the battery in place.
Reconnect the positive terminal - Tighten the clamps using a wrench.
Reconnect the negative terminal - Tighten the clamp with the wrench.
Apply battery lithium grease - Spray the terminals with lithium grease to prevent corrosion.
Close the hood - Shut the hood of your car firmly and start your car. Check that all the electronic devices are working properly.
Dispose of the battery at service garages, auto supply stores, and recycling centers. There may be a small fee for the service, but throwing the battery away as normal garbage is not an option.
In the US, most battery retailers charge a deposit on the battery, which will be refunded with the return of an old battery.