Lightning is caused by a buildup and then discharge of electric charge in our atmosphere. This is caused by small frozen particles in a cloud bumping into each other again and again to create electric charge. Eventually, the positive charged particles congregate at the top of the cloud, and the negative ones near the bottom. The charged regions in the atmosphere then eventually temporarily equalise themselves through a lightening flash or strike.
Thunder often accompanies lightening and occurs because the sudden increase in temperature and pressure in the air from lightning causes a very quick expansion of the air surrounding the lightning bolt/flash and this causes a sonic boom, or very loud noise.
Cool fact – you can estimate how far away the lightning flash is away from you by counting the seconds between the flash and the thunder which follows and multiplying this by the speed of sound! I’m a tad terrified of lightning storms so I think doing this calms the nerves 😉
As Lauren has said, one can calculate how far the storm is away by counting the seconds between the flash of lightning and the thunder. One just needs to remember the speed of sound, 340 metres/s, meaning that in 3 seconds sound travels roughly a kilometre. So count the seconds between the flash and bang and then divide by 3 to get the distance. It is a fun game.