How to Get Rid of Gnats and Flies

Plus how to keep these pesky flying creatures away from your home.

A woman washes lemon at the kitchen sink.
Keep gnats and flies out of your kitchen.
Sviatlana Yankouskaya / Shutterstock

Gnats and flies may enter your home—or linger around your backyard—despite being decidedly unwelcome. While they’re small and don’t bite, a swarm of flying creatures by the fruit bowl, around the trash or kitchen drain, or circling around a houseplant is a real nuisance.

And as the weather heats up, you’re more likely to have flies around. They’re most active in warm and sunny weather, says Brittany Campbell, an entomologist with the National Pest Management Association. “Fly activity is going to be highest in late spring throughout summer, until temperatures begin to decline below 50 degrees Fahrenheit.”

Find out how to prevent flies and gnats from entering your living space—and how to get rid of them if they make it in.

Know your enemy.

There are a few different types of flies and gnats that you’re likely to encounter:

  • Fruit flies. They’re small and short-lived, with a lifespan of less than two weeks. They can have red or dark eyes, and adults are attracted to light. Given their name, it’s no surprise that they are often found by fruit. Anything moist is appealing, though, so you may also find them on damp mop heads, Campbell notes.
  • Fungus gnats. These flying bugs are often mistaken for fruit flies, says gardening expert Krista Green, writer at Zone 3 Vegetable Gardening. Fungus gnats can be a huge annoyance when they infest your indoor plants, but they can also damage the young roots of seedlings. They’re typically found “on fungi growing in the soil and moist decaying organic matter,” Campbell says.
  • Drain flies. “Drain flies have a fuzzy appearance as their bodies and wings are very hairy,” Campbell says. You may find them by drains—in the bathroom or kitchen—but any moist area, such as the condensation pan under a fridge or the saucer under a plant, is an ideal breeding ground.
  • House Flies. They’re gray with black stripes on their thorax and they make a buzzing sound as they fly. They eat human food and pest waste. And while they don’t bite, they can spread many pathogens, including typhoid fever, E. coli, and cholera.

In general, these pests are mostly a nuisance. That said, fruit flies “are also capable of contaminating food with harmful bacteria and disease-causing pathogens, since they are typically found in unsanitary conditions,” Campbell says.

Indoor plants sit on top of a midcentury modern cradenza.

Houseplants can harbor gnats.

Followtheflow / Shutterstock

How to Prevent Flies and Gnats

Here’s how you can help keep these critters out of your home and outdoor space:

  • Prioritize cleanliness. “The best method for preventing flies in the home is through vigilant sanitation,” Campbell says—that means taking out the trash or compost daily, cleaning countertops each night, promptly disposing of produce as it starts to turn, rinsing recycling, and so on. Store most produce in the refrigerator, rather than on countertops, to extend how long it keeps and to restrict access for flies.
  • Stop bugs from getting in. Keep screens in good condition. Very tiny gnats and flies can make it through the weave in screens, so close your windows if that occurs, Campbell says. It’s also a good idea to patch up holes around window frames, joints where siding meets the foundation, and air intake and exhaust valves, says Thomas Marbut, general manager and corporate trainer at Mosquito Squad. “Caulk is your best friend if you need to seal entry points throughout your home.”
  • Remove moisture. If you have stagnant water outside or in your bathroom sink drain, fix the underlying issue. And watch for damp towels and mops, too.
  • Take care of pet waste promptly. Empty the litter box promptly and scoop right after your dog goes in outdoor spaces.
  • Be thoughtful with indoor plants. While outdoor fungus gnats aren’t typically an issue, they can be a problem with houseplants, Green says. Since they thrive in moist soil, try bottom watering plants, she suggests. To do this: Set plants in a water-filled tray for 15 minutes, rather than watering from the top. Sprinkling cinnamon or diatomaceous earth (DE) on top of the soil, or adding an inch-thick layer of sand on top of the potting soil, can also be a deterrent.
  • Take precautions outside. “If you are cooking outdoors, keep flies and gnats away by covering all food when outside,” Campbell says. Be smart about trash, too: Place it in cans with tight lids, and put trash cans far from where you’re sitting or cooking. 
  • Tend to landscaping. “Managing overgrown vegetation and removing water sources will help limit fly breeding and resting areas around a patio or deck,” Campbell says. Some plants—such as geraniums, lemon thyme, and lavender—may also act as a natural deterrent to gnats, Marbut says.
Eco-friendly kitchen supplies sit on the counter next to a modern black kitchen sink and faucet.

Deep clean kitchen surfaces, including the drain, to help get rid of flies and gnats.

July Ko / Shutterstock

How to Get Rid of Gnats and Flies

Even the best efforts are sometimes foiled by a hole in the screen or a rotting apple. If gnats or flies do make it inside, try these tactics to get rid of them. 

Remove rotten food.

“If you discover a gnat or fly infestation in your home, dispose of the infested item,” Campbell says. Place it in a sealed trash or compost container outside and then clean the area where flies and gnats were gathering. 

Clean out the drain. 

“Bleach is usually the best and most effective method of removal for gnats that tend to crowd around drains,” Marbut says. You can pour a half cup of bleach diluted with a gallon of water down the drain. For a more eco-friendly option, swap the bleach for vinegar.

Set a trap.

Common pantry items can help you catch lingering pests:

  • Apple cider vinegar trap. Mix together a few tablespoons of apple cider vinegar, a few drops of dish soap, and some sugar in a bowl, Marbut says. Then, place it in a spot where the gnats are gathered. “This apple cider vinegar blend will attract gnats, and the dish soap traps them,” he says.
  • Fruit trap. “Fill a jar with rotting fruit and cover with plastic wrap poked with holes,” Marbut says—the gnats will be attracted to the fruit, then become trapped within the jar.

If there are pests around plants, try repotting them in fresh soil, Green says. You can also use yellow sticky paper—available at hardware stores and nurseries—to trap insects, she says. Gnats will fly into the paper and stick to it (just be cautious with this approach if you have pets).

When to Call in the Pros

DIY strategies are often enough to vanquish flies and gnats, but “when the infestation gets to the point where these basic remedies won’t work, it’s time to call a professional to get to the root of the problem and clear your home of these unwanted pests,” Marbut says.

Pros can also help find the areas that are attracting pests, Campbell notes. For instance, professional cleaning may be required to remove breeding grounds for flies or a plumber may need to identify if it’s a broken pipe attracting gnats below your home.