Lightning is caused by the buildup of static electricity in the atmosphere, typically during thunderstorms. When the negative and positive charges separate within a cloud or between a cloud and the ground, they create an electrical discharge in the form of lightning.