Light coming from distant stars passes through different layers of air. Each layer differs from the other in their optical densities. Hence light undergoes successive refraction. Since stars, at a greater distance, they appear like a point source. The rays of light appear to come from different points on reaching the eye after refraction. This is the reason for the twinkling of stars.