Lightning is an electrical discharge in the atmosphere, very similar to a spark. It is the electrical breakdown of insulating air to provide a transient, conductive path along which a current can run to neutralize the charge.
Lightning mostly occurs in thunderstorms.
Other situations in which lightning occurs are dust storms, blizzards, volcanic eruptions and nuclear explosions. It seems to be a phenomenon occuring in large volumes of particle clouds when they are being transported in the atmosphere. In thunderstorms, charge is being separated by what is thought of being several processes. All these can produce charge separation, but not much is known about which effect plays the most important role in cloud electrification. Simplified, a thunderstorm has a positively charged top, a negatively charged lower section, and a small layer of positive charge at the cloud base which is carried up a little bit into the updrafts.