First, let's examine how clouds form before you can understand how a cumulonimbus forms!
How Do Clouds Form?
Clouds form when "invisible" moisture in the air (water vapor) is forced to condensate on microscopic particles (i.e. pollen and dust) to form tiny "visible" droplets!
Condensation occurs when the air is cooled down to its "dew point" temperature.
The Kettle Experiment
Consider the "cloud" that forms over a boiling kettle in a cold room. That, in a nutshell, is how clouds form.
Why does the "cloud" over the boiling kettle disappear almost as soon as it forms? Because the surrounding air is dry enough and warm enough to prevent condensation.
The hot and very moist air gushing out of the boiling kettle appears as steam.
Steam is a "cloud" in its very first stage ... which evaporates almost instantly (return to gaseous form called moisture or water vapor) because the air in the room is too dry and warm.
A Room Full Of Cloud
The colder the air in the room, the sooner you will be able to saturate it with water vapor ... if the boiling kettle does not run out of water before then!
If it is relatively cold in the room, a "cloud" would soon form and fill the room! It would then be called "fog" ... just like when you take a long hot shower in a cool bathroom!
Clouds Are "Cool"
Moist air must be cooled for clouds to form. Here is how the cooling process is made to occur in the atmosphere.
The atmospheric pressure at the earth's surface (at the bottom of the atmosphere) is at its highest. Air pressure decreases with altitude.
When air is forced to rise, it expands because the pressure exerted on it decreases.
When air is forced to expand it becomes cooler. It's the law ... one of the fundamental laws of physics governing gases.
Clouds Need A "Lift"
The water vapor coming out of the boiling kettle is the result of the convective process triggered and maintained by the heating element of the stove under the kettle.
The convective process is one of the five (5) lifting processes necessary for cloud formation.
Often, only one lifting process needs to be active for cloud to form. Sometimes more than one are required.
Convection occurs when the sun has heated the surface of the earth. The air in contact with the earth is heated by the hot surface.
Bubbles of warmed air begin to rise ... like hot air balloons ... or like hot air bubbles rise from the bottom of the water in a kettle heated by the hot stove element.
Orographic lift: when air is forced to move up a sloping plain, large hills or a mountain range.
Frontal lift: when a cold front kicks up the air ahead of it like the bow of a big ship ... or when the air slips up the slope of a retreating cold air mass (that is called a warm front).
Mechanical turbulence: when air moves rapidly over rough ground it churns and produces rising eddies sometimes hundreds of meters above ground ... just like strong rapids spray water high up in the air.
Convergence: the air spiraling in toward the center of a low pressure, trying to fill the relative void ... somewhat like the water rushing toward the drain when you pull the plug!
The difference is that, in the case of a low pressure area, there is no drain! The air spiraling in to fill the "low" collides in the center of the low ... and has nowhere else to go but up!
So How DO Thunderstorms Form?
Thunderstorms are convective type clouds. They start small, just like any other fair weather cumulus. What makes a small cumulus grow to the (comparatively) gigantic proportions of a thunderstorm?
As an example of a favorable situation, think of a hot muggy day. By mid-morning, the sun is already beating down hard. Soon big cumulus clouds form in the blanketing haze.
By the time the sky becomes overcast ... it's too late. The sun has already heated the surface of the earth enough. The process is on...
Thunderstorms need the three conditions to form.
Lots of warm moist air.
Strong and prolonged lifting (at least one lifting process must be active, usually convection or frontal lift).
But most of all an unstable atmosphere to high levels.
The atmosphere is considered unstable when the rising moist air never gets to cool down to (at least) equal the ambient temperature aloft.
In other words, as long as the ambient temperature aloft is colder than the rising moist air ... the moist air "bubbles" continue to rise.
Sometimes the thunderstorm cells will tower well above 10,000 meters and generate all types of lightning!
When the atmosphere is extremely unstable, the thunderstorm can continue to grow and eventually produce lightning storms ... and even grow into the next stage: a tornado!