The mechanism of lightning is not yet completely understood. According to the best current model, during a thunderstorm, friction caused by turbulence within clouds charges their ice crystallites, usually with positive charges concentrated on the upper surfaces of a cloud and negative charges on the lower surfaces. On the ground, positive charges are induced, although in much smaller numbers. Ionized air becomes a conductor, enabling charged plasma to branch out from the cloud (step leaders) and discharge to the ground through multiple random paths.
For a detailed discussion, see the Wikipedia entry for Lightning.