The Days He Lived and Loved and Laughed

Moths frequently appear to circle artificial lights, although the reason for this behavior remains unknown. One hypothesis to explain this behavior is that moths use a technique of celestial navigation called transverse orientation. By maintaining a constant angular relationship to a bright celestial light, such as the moon, they can fly in a straight line. Celestial objects are so far away that, even after travelling great distances, the change in angle between the moth and the light source is negligible; further, the moon will always be in the upper part of the visual field, or on the horizon. When a moth encounters a much closer artificial light and uses it for navigation, the angle changes noticeably after only a short distance, in addition to being often below the horizon. The moth instinctively attempts to correct by turning toward the light, thereby causing airborne moths to come plummeting downward, and resulting in a spiral flight path that gets closer and closer to the light source.

https://en.wikipedia.org/wiki/Moth#Attraction_to_light