That's called static electricity and it is the energy that is formed in a storm cloud when rain droplets and tiny pieces of ice rub together. They are charged with either negative electricity and stay near the bottom of the storm, or with positive electricity and float to the top. Since opposites attract, the positive and negative charges race towards each other and when they meet, they complete an electrical circuit, which causes the bright flash of lightning that we see.
Thunder is actually the noise that lightning makes as it travels through the air.
The lightning heats the air around it to over 60,000 degrees - so, the air gets very hot and expands very quickly, causing a kind of explosion. The explosion causes a huge push of sound waves, which is the thunder we hear. In the race between thunder and lightning, lightning will always win because light travels faster than sound. Light travels at 186,000 miles per second, but sound only travels one mile every five seconds near the ground. So, to see how far away lightning is from you, count the seconds between the lightning and the thunder and divide it by five - that's how many miles away the storm is.