Lightning is caused by the buildup of static electricity in the atmosphere, primarily within clouds. This buildup of electrical charge occurs due to the collision of ice particles and water droplets within a cloud. When the charge difference becomes strong enough, it is discharged as a lightning bolt, which is a rapid and powerful flow of electricity between the cloud and the ground or between two different parts of the same cloud.