What causes thunder? What causes thunder to rumble sometimes and why does it sound like a crack or bang at times?

Thunder is caused by the rapid heating (and then cooling) of the air from lightning. Lightning is exceptionally hot so when it passes through the air, it heats the air very rapidly. This heat causes a rapid expansion of the air column followed immediately by rapid contraction of the air column due to the air cooling back down. This sends out a shockwave through the atmosphere, which results in the sound that we refer to as thunder. If the lightning hits close by, the thunder will sound like a crack or bang. If the thunder is caused by lightning that is far away, it will rumble and slowly fade away. The reason that it rumbles for a long time sometimes is this... At first, you are hearing the sound created by that part of the lightning that is closer to you. Then, as each passing second goes by, you are hearing the sound of the parts of the lightning that is further and further from you. This is especially true when the lightning is cloud to cloud, which means that it is nearly horizontal, relatively speaking. Lightning can stretch for a long distance so you can understand why the thunder can last for quite a while from one lightning strike. When cloud to ground lightning hits close by, it is vertical for the most part, which means that much of the sound will get to you about the same time. In other words, a large part of the lightning strike is roughly the same distance from you when it is mostly a vertical (or cloud to ground) strike, so you hear much of the sound, or the thunder, at the same time. This is when the thunder sounds like a crack or a bang and it can be especially loud. You should always take cover when you hear thunder, especially when it is loud and sounds like a bang.