Thunder is caused by lightning. When lightning passes through the air, it heats the air extremely quickly. The heated air expands suddenly, creating a pressure wave that travels as sound.

Why thunder can rumble

Thunder can sound like a sharp crack or a long rumble because sound reaches you from different parts of the lightning channel at slightly different times.

Thunder and lightning distance

Light travels much faster than sound, so you see lightning before hearing thunder. Counting the seconds between them can give a rough idea of how far away the lightning is.

Thunder is the sound side of lightning, not a separate event.