There are a few different types of lightning, the lightning previously referred to (from cloud to ground),the ground acts as a pool of electrical charge, and when the clouds gain charge, the ground attempts to balance out the charge by gathering the opposite charge beneath the cloud system. When the difference between charges becomes great enough that leads to a breakdown of air between the charges. When this break down occurs that is when lightning occurs and it either occurs from cloud to cloud or from ground to cloud. What usually happens is the lightning starts at the ground and flows upward, it happens vice versa too, however it usually begins at the ground. To go into further depth, when a pool of negative charges are collected at the bottom of the cloud, that forces the negative charges on the ground to be pushed away. When this happens, that leave the charge of the ground positive. So usually a stream of negative charge travels down to the postively charged ground, when this occurs a stream of positive charges comes up from the ground because the two opposite charges attract. When the streams of charge come in contact with each other they create a very conductive path which allows a sudden down surge of electrons to jump to the ground. This is the lightning.
The whole reason for the lightning is because of the basic electromagnetic principal that opposite charges attract. The reason that opposite charges attract is so that they can reach an equilibrium. Two oppositely charged objects want to be close enough so that they can discharge and become neutral or reach equilibrium. The different charges are due to the amount of electrons or protons in an atmosphere, electrons have a negative charge of 1.6 x 10 to the negative 19th coulombs, enough electrons and the charge in the atmosphere (in this case cloud) is negative so a deficit of electrons creates a positive net charge. To explain the breakdown of air that creates lightning, ionization will have to explained. When two opposite charges are separated and cannot exchange electrons through contact, they must exchange electrons through a medium. In the case of electric storms, the air becomes the medium for this exchange. However air is not conductive, so this means that electrons cannot pass through it easily, for this problem to be changed the process of ionization must occur. This occurs when when a large amount of charged particles try passing through the medium this then causes the electrons and protons of the medium to separate, when that happens it creates a path between the two regions, and then the charges can flow.
Lightning as you can see is a very fascinating topic! Charges are all around us even when we can't see their effects, so its cool to be able to actually SEE the results that charges have in our world and in our atmosphere!