It often seems like fruit flies just appear out of nowhere. In fact, it appeared that way to so many people that they believed that fruit flies were a product of spontaneous generation — spawned supernaturally from rotting fruit or meat. This theory was disproved a few hundred years ago and we now know the truth about these tiny nuisances — I mean creatures.

The truth is that fruit flies (or Drosophila melanogaster, as they are scientifically named) are stealthy little guys that seem to smell rotting fruit from miles away. They do not come from the inside of the fruit, but rather come from outside once the fruit in your house starts to go just past ripe (as long as it’s out on your counter and not in the refrigerator, that is).

“But all my doors and windows are closed,” you say! “How could they possibly get in?” Fruit flies are so tiny that they can enter through even the tiniest of crevices around windows or doors and can even fly right through your window’s insect screen. You see, when a fruit is overripe or starts to go bad it begins to ferment, producing alcohol, which attracts fruit flies. They continue to gobble up the fermenting fruit, and in the process, lay hundreds of eggs which hatch into larvae in mere hours. If you ever went out of town and left a bowl of ripe fruit on the counter, then you know this all too well. Because upon your return, your kitchen will be a fruit fly fiesta, complete with sombreros and piñata.

(By the way, you can even bring fruit flies home from the store with your groceries if the fruit has already started to rot there.)

So how do you get rid of fruit flies?

Well, first things first — you need to get rid of the offending fruit or vegetable. Even after the fruit is gone though, fruit flies can live on the bottom of mops, dirty drains and old sponges.

A tried and true method I have used is to smack them silly — though often you’ll miss them (even though they are floating right in front of your nose, somehow they seem to escape — dagnabit) and you’ll end up with sore hands in the process.

But this still doesn’t get rid of every single last one of them — and that is crucial if you don’t want to be killing fruit flies for the next month. So what to do?

Many suggest putting beer in the bottom of a glass bottle with a paper funnel out the top. The fruit flies are attracted to the bait and can get in quite easily, but somehow never figure out how to get out. All you have to do is leave this out for a couple hours, cap the bottle when you’re done and voila — fruit fly problem resolved.

Well there you have it, folks — now you know where fruit flies come from, and you know how to get rid of ‘em. For more creative ways to rid your home of fruit flies, check out Matt Hickman’s story on that topic.