Clouds become electrically charged,the upper portion is positively charged and the lower portion is negatively charged.There are many explanation for how the cloud acquire charge,the best explanation is that electric charge is due to the collision between ice,water and water vapor. When the electric field in the cloud increases and increases,electrons in the cloud start to repel electrons in the ground surface causing it to become positively charged.Now,we have negative charge - air-positive charge (see figure),but air is an insulator and the lightning needs a path,here comes air ionization process where air become ionized .Then what’s called a stepped leader which is an invisible discharged path that moves downward from cloud to ground.And another leader is then created upward from Earth to cloud.When both make contact visible lightning occurs.
The Earth has its own magnetic field , it acts like there is huge bar magnet buried inside,but this bar magnet is not on the earth rotational axis it is shifted by some angle.The south of the bar magnet is on the magnetic north and the south polarity is on the magnetic north(image).As opposite polarities attract the magnetic needle (north) is attracted to the south polarity in the magnetic north.That’s why the needle always points north.If you want to know “why earth has magnetic field?”go to letter E.