Summer's in and so are the moths. But why are moths attracted to our lights, anyway? You may have also seen moths steer straight into a candle flame. Why do they do that?
Candle lights and light bulbs are artificial lights, so they're relatively new in the grand scheme of things. Before this, moths could rely on the stars and the moon to guide them through the night. The stars and the moon are at what's called optical infinity. This means that the rays that come from them are parallel. Consequently, this makes them great for using a sort of compass. Insects, like moths, can, therefore, rely on the moon and the stars to steer in a straight line. Interestingly, they can also use the light as a way to find their way back home. As insects have compound eyes, they can keep the light in a particular part of their eye (or in an ommatidium to be more precise).
The light serving at as a guide works beautifully when the light is at optical infinity so that the rays are parallel. When this isn't the case, moths find themselves steering towards the light in a spiral fashion. With the case of candle flames, this unfortunately means the end of the moth.
Before you run away thinking moths are silly for flying into a flame, you have to first realise that candle flames aren't something that moths tend to come across often. More often that not, moths do find their way around by using celestial lights. It's just that we're not paying attention.
This fun little fact came from the God Delusion by Richard Dawkins, which is an interesting book in itself. I've condensed this topic down, so for a fuller description of this seemingly evolutionary mishap, I'd recommend consulting the book.