Light from stars passes through the atmosphere. The different layers of atmosphere are moving hence, its refractive index is changing. As the light is bent at different angles at different points of time, their position does not appear fixed and hence, they twinkle.