To say that there’s a ‘theory’ behind lightning and thunder is a bit of a fallacy these days because science has, at the very least, more or less figured out thunder. Lightning is still a bit of a mystery, or at least the process by which clouds are charged is, though the process through which lightning travels to the ground and strikes vulnerable objects seems rather set in stone.
The process by which lightning forms typically begins with the water cycle generating a rain storm (though not always – lightning has been known to appear during other atmospheric phenomena, though by far it’s more often associated with rain). Water on the ground is turned into vapor by the heat of the sun, and when that vapor is released into the air it travels upwards.
As the vapor travels higher and higher it begins to encounter cooler layers of air, which begins to change the vapor back into water. This process results in the formation of clouds and can, in sufficient amounts, create rain clouds. This water, now heavier than air and pulled down by gravity, falls to the ground again.
During this process – and this is where the science can become a bit fuzzy – a certain amount of charge can build up in the clouds overhead. This may be the result of any number of things, though for the purpose of this article we’ll stick with the Electrostatic Induction Hypothesis which presupposes that ice crystals in the clouds, passing by the falling water droplets, travel up while the water goes down, generating a charge between the two that can create a bolt of lightning that first travels between the top and the bottom of the cloud, and then down into the ground (or, sometimes, between clouds). There are numerous theories as to charge generation, however, several of which are detailed in this handy Wikipedia article.
The lightning, seeking out the opposite charge, can strike just about anything on the ground or in the air. As it’s traveling through the air lightning has the effect of super heating surrounding air molecules, causing the air to expand exponentially in a very short period of time. The result of this is a short, rumbling shock wave that manifests several seconds later as thunder. The fact that thunder always comes after lightning was one of the main factors in discovering that light travels faster than sound.
Regardless of how lightning and thunder form, it should be common sense by now that seeing and hearing the pair is a sign of trouble. Whenever there’s a thunderstorm you should always head for the nearest convenient dwelling and ride out the storm, as lightning bolts can strike almost without warning and are more than capable of killing a person.