Thunderstorms result from the rapid upward movement of warm, moist air. They can occur inside warm, moist air masses and at fronts. As the warm, moist air moves upward, it cools, condenses, and forms cumulonimbus clouds that can reach heights of over 20 km (12.45 miles). The thunderstorms are associated with the cumulonimbus clouds. These clouds normally form on warm sunny days but they can also be found on cold front. But this question is asking about the Thunder i.e. the sound produced. The lightning generates between 100 million and 1 billion volts of electricity and can heat the air to around 50K°F. The rapid expansion causes the shock waves. Thunder happens because the lightning would heat the air at huge temperatures and the air expands so fast that it make a loud clap of thunder.