What is Thunder?
Thunder is caused by the rapid expansion of air surrounding a lightning bolt.
As lightning strikes, it raises the temperature of the surrounding
air to around 27,000 C°. The heated air is compressed and
explodes outward from the channel, forming a shock wave of
compressed particles in every direction. Like an explosion, the
rapidly expanding waves of compressed air create a loud booming
noise.
The bolt of lightning is seen long before its thunder is heard
because the sound travels around 343
m/s though air which is much slower
compared to the speed of light.
The sound of the thunder is affected by the shape of the lightning
bolt. For nearly vertical bolts, the shock-waves closer to the
ground reach your ear first, followed by the shock-waves towards
the top. With bolts that are forked the sound waves will bounce
off each other and be much more sporadic as they approach your
ears.
https://www.nasa.gov/missions/science/MARSS.html
Each second between the lightning and sound of thunder represents
nearly 300m, and is a useful tool in determining how far away
lightning is.