The story
You are indoors when lightning flashes beyond the window. For a moment, the room brightens. Then comes the crash. The light and the noise seem like separate events, but the thunder begins along the lightning's path.
Lightning sends a huge electrical discharge through air. The narrow channel heats extremely fast. The National Weather Service says the air in that channel can reach up to about fifty thousand degrees Fahrenheit. That does not mean the entire cloud reaches that temperature. The extreme heating happens along a thin path.
Hot air expands. Here, the heating is so sudden that the expansion creates a strong pressure disturbance. It spreads away from the channel, becoming the sound wave we call thunder. A flash makes the air move, and moving air delivers the crash to your ears.
Why does thunder arrive late? Light travels much faster than sound. Over the distances around a storm, the flash reaches your eyes almost immediately. Sound takes much longer to cross the same space. A pause after the flash is mostly the travel time of the sound, not a wait while the lightning decides to make noise.
The lightning channel can be long and crooked. Some parts are closer to you than others. Their sound arrives at different times, which helps explain a rolling rumble instead of one short snap. Reflections and the air's conditions can change what you hear too.
From a safe place inside, counting about five seconds between a flash and its thunder gives a rough distance of one mile. That estimate is not a safety boundary. If you hear thunder outside, move into a substantial building or a hard-topped vehicle. The next lightning strike can be closer than the last one. The fascinating sound is also a warning.