Lightning is an electric discharge, or electric current, in our atmosphere that forms from opposite charges within thunderstorm clouds. These clouds, otherwise known as cumulonimbus clouds, are made up of ice crystals and water droplets that collide with one another and begin forming charges as a result of the collisions. After some time, the charges begin gathering at the top and also at the bottom of the thundercloud.
The negative charges, or electrons tend to gather near the base, while the positive charges, also known as protons, start gathering near the top-the anvil. Because opposites attract, and negative charges are located near the base of the cloud, positive charges begin gathering around tall objects near the ground. The opposite charges then lead to the lightning to strike, but meeting in the middle between the object and the cloud.
This just describes one type of lightning-cloud to ground. There are two more main types of lightning, intracloud & cloud to cloud. Intracloud lightning is lightning that occurs within one cloud itself. This is the most common lightning and the type you see when the sky tends to flash. The other type, cloud to cloud, occurs obviously from one cloud to another within the vicinity.