The difference between thunder and lightning is that lightning is electromagnetic energy and thunder is sonic energy. Lightning actually causes thunder by rapidly heating and expanding the air around the path of the strike, explains a Library of Congress website.
Lightning is a flow of electrons between the earth and the atmosphere, and thunder is the sound made when those electrons interact with the surrounding air. When lightning strikes, it heats the surrounding air to nearly 50,000 degrees Fahrenheit in less than a second. This causes the air immediately around the path of the lightning bolt to expand to over 100 times higher than normal atmospheric pressure. This rapid expansion of air creates a pressure wave and the audible sound known as thunder.
Since thunder and lightning are two different forms of energy, they travel at predictable speeds through the same medium. Using this relationship, the distance from a given lightning strike to an observer is roughly estimated by counting the elapsed time, in seconds, between the strike and the resulting thunder. Each five-second interval that passes after a lightning strike is approximately equivalent to five miles of travel for the sound wave. Another good indicator of the distance from a given lightning strike is the volume of the accompanying thunder, as the volume of the thunder increases as lightning strikes become closer to the listener.