To understand the forces behind thunder and lightning, one must recall basic information about electricity, that things can become either positively or negatively charged with electricity and that two things with opposite charges will attract each other. As the opposite charges become stronger, the attraction becomes greater; eventually the attraction becomes strong enough to result in a discharge that makes the two things electrically neutral again.
Lightning results when one cloud full of moisture develops an opposite charge in relation to another cloud. The pressure continues to build until there is enough pressure to break down the air separating the two clouds. A discharge occurs to neutralize the opposite charges in the two clouds, and this discharge is what we see as lightning. As this discharge of lightning is occurring, the lightning follows the "path of least resistance"; it therefore does not follow a straight line but zigzags in order to find the easiest route.
Thunder occurs during the discharge of electricity. As the discharge occurs, the air in the vicinity expands and contracts rapidly; the rushing air currents collide, causing the sound that we hear as thunder. Light travels much faster than sound (the speed of light is 186,284 miles per second, while the speed of sound is 1,100 feet per second), so we see the light first and then hear the sound later. Of course, the farther away the thunder and lightning are, the greater the lapsed time between the two. In fact, the amount of lapsed time between the two can be used to determine how far away the thunder and lightning are.