I think the guys in the space zone might be able to give a better explanation but I’ll try.
Clouds can build up electric charge. There are a few different theories about why this happens: from particles bashing off each other in the cloud to the earth’s magnetic field taking part. Anyway, this build up of charge is unstable and eventually reaches a critical point and is discharged. The way this happens is not that well understood coz it’s quite hard to study clouds since they are far away and storms can be dangerous, and also because this all happens so quickly. When this electrical charge is discharged you get a lightning bolt. A lightning bolt is a massive bolt of electricity and it can heat the air really quickly to really high temperatures as it passes. As the air heats up, it expands and rushes out as a shock wave causing the thunder that accompanies lightning.
You can actually get different types of lightning: cloud to cloud, cloud to ground and even ground to cloud (but this is artificially done)! The most common one we see is cloud to ground.
In honour of Thanksgiving I thought I’d let you know that some of the earliest work proving that lightening is electricity was carried out by one of America’s founding fathers, Benjamin Franklin. He proposed an experiment to capture some electricity from lightening in a special jar by flying a kite during a storm, and actually carried out the successful experiment himself in 1752.
Other scientists died performing the experiment or similar experiments with lightening rods (which he also invented), but Franklin survived and went on to sign the Declaration of Independence, become US Minister to France, invent Bifocal glasses, and studied demographics, ocean currents and conductivity, among other things.