Compost Magazine

Composting tips, advice and science.

Close up of a blow fly.

14 Effective Ways To Prevent and Control Flies In Compost 

When a compost pile is built correctly, you shouldn’t have many problems with flies. 

In fact, The Composting Handbook notes that composting is a great way to reduce the number of flies on farms. 

What’s more, a few flies are not really a problem. In fact, they can even provide a benefit for the compost heap. 

In the compost food web, they are considered a physical decomposer.

They help to break down compost material, and both their eggs and maggots can be a source of good for other compost creatures. 

As we shall see, there’s even a method of composting that primarily relies on flies to do the work!

Still, if you have a lot of flies it’s both an annoyance and a sign something has gone wrong. 

What are the flies in compost?

With over 120,000 types of flies in existence, we’re going to limit this section to some of the most commonly found in compost! These include: 

A vinegar fly stands surrounded by droplets of water.

Vinegar flies (Drosophila)

These are small flies that can attend compost heaps in great numbers! They are attracted to the smell of fermentation (so watch out for rotten fruit), while their larvae eat microorganisms in the compost heap. They are often called fruit flies.

Blow fly close-up

Blow flies (Calliphoridae)

These are often referred to as carrion flies, as their larvae feed on decaying flesh. They vary in size, color, and other characteristics, but all have a distinctive, metallic-looking sheen. They are attracted by meat and manure. 

House fly on a wooden table.

House flies (Musca domestica)

House flies are usually gray or black in color and have four dark stripes on their thorax. They are known for their ability to spread diseases, as they can carry and spread a variety of pathogens.

Solider fly on a white background.

Soldier flies (Hermetia illucens)

Soldier flies are so good at decomposing materials, they’re used as a form of composting. The larvae are voracious eaters and consume high-nitrogen material. Their larvae are also used as a source of food for both humans and animals! Soldier flies also produce strong-smelling leachate which can deter house flies. 

YouTube video player

Reasons for Compost Fly Infestation 

When a compost heap is active, the conditions are inhospitable for flies. What’s more, the material is rapidly broken down, making it unsuitable for fly consumption.

So many of the causes of a major fly infestation are the same as those for an inactive compost pile.

They include:

Not enough air

When there is not enough air in the compost, the compost becomes slow, the material breaks down more slowly and the compost cools down – all creating great conditions for attracting flies. 

Too much moisture

Compost should hold in the region of 45-60% moisture.

If there is more water than this, it can force air out of pores. This leads to anaerobic composting which causes both slow decomposition and foul odors.

Imbalance of materials

A mixture of high carbon (brown) and high nitrogen (green) materials is essential for an active compost heap. 

In particular, some green materials, such as grass, are high in water content. Without dry browns to balance them, they can become matted and wet, again forcing oxygen out of the compost heap. 

Food on the outside of the compost 

Some organic materials attract flies more than others. You probably don’t need me to tell you that materials such as fish, meat, dairy, manure, and so on can attract flies, while fruit and vegetable waste can attract vinegar flies.

However, this tends to be when the food is on the outside of the compost, not when it is buried inside it. 

Flies on compost.

Prevention of Compost Fly Infestation 

You’ll notice some overlap between this and some of our other guides.

That’s because many of the steps you need to achieve good, hot compost (that doesn’t smell!) are the same as those needed to prevent a fly infestation. 

Check and Adjust Moisture Content

As we’ve seen, too much moisture leads to anaerobic (without air) composting, which can be a cause of flies in compost.

You can monitor compost moisture levels by squeezing it in your hand.

If it feels like a wrung-out sponge, it has the right consistency. If it’s wetter, add some absorbent material such as shredded paper or sawdust and/or turn the compost.

If you don’t like getting your hands dirty, you can use a moisture meter.

If you have a large compost heap, this is best done by turning the compost. Check each layer and add water if needed. I generally find I only need to do this once.

For more tips see our guide to moisture in compost

Monitor Temperature 

Not everyone pursues hot composting, but it is a good way to prevent flies. If you do, it’s handy to monitor the temperatures. If it’s not getting hot enough, there are a number of things you can do to increase the temperature.

These include 

  1. Adding high nitrogen materials such as grass, urine or chicken manure. 
  2. Using a hot water bottle to stimulate thermophilic bacteria. 
  3. Adding insulation, such as a compost duvet to a compost bin. 
  4. Combining two compost piles in one to build size and internal heat. 

Also see: Hot v. Cold Composting | Compost Thermometer Guide

Aerate compost

Ensuring there is enough oxygen in the compost will ensure materials break down fast and increase the chance of hot composting. 

There are many ways to aerate the compost. These include:

  • Placing sticks at the bottom of the compost when you start building it. 
  • Poking holes in with an iron bar. 
  • Using a compost aerator. 

Also see: 11 Ways to Aerate the Compost Pile.

Turning: Breaks the fly’s reproductive cycle

Turning, of course, is another way of aerating the composting (and helps you check moisture levels). It deserves a separate mention, though, as it also disturbs the fly’s reproductive cycle. 

The Compost Handbook recommends turning compost every four days if you are using it to prevent fly infestation. That’s because some types of flies breed every five days. 

That might be too much to do on a regular basis, but it might be worth doing if you have a current fly problem. (It’s also cheaper than a gym membership!)

Use a mix of high carbon (brown) and high nitrogen (green) materials

The bacteria in compost need both nitrogen and carbon to break down organic material over the longer term. 

Too much high-nitrogen material causes nitrogen to be lost, ammonia to be released and smells to be released from the compost. If there are too many brown materials, the process will be slower and the compost will not heat up. 

Aim for roughly 50% green and brown – but do note that you don’t have to get it exactly right.

(Some guides recommend two parts green to one part brown, but either will work. See the C: N ratio for details, as well as examples of greens and browns.) 

Include absorbent materials

Dry brown materials are often perfect for absorbing moisture. 

Shredded paper does well here, although it does break down slowly and can hang around in your compost for a while – I’ve switched to sawdust for this reason. 

Those dry brown materials also often act as bulking agents, which help trap air pockets in your compost.

Exclude or bury smelly foods

As we have seen, certain materials attract flies more than other materials. 

There’s a simple answer here – either, avoid these foods or bury them in the compost. 

I go at least a spade deep into the compost, and ensure it is well covered – and a bit deeper if I am burying a dead animal.

Use a biofiltration layer

This sounds fancy, but it’s easy to put into place. 

Simply place a layer of material over your heap or the top of your bin to capture smells. This can include items such as straw, sawdust, woodchops or even mature compost. 

(The last is a technique often used in commercial operations when compost is made in windrows.) 

Using a lid

Using an air-tight lid on kitchen bin systems is a great way to prevent flies, but it’s not such a good idea for typical outdoor systems. 

To compost effectively, you usually need air, which requires some way of ventilation. And if there’s any ventilation at all, flies will get into the compost. What’s more, a tight-fitting lid can stop creatures that feed on the fly and their larvae from getting into the bin. 

However, some systems do use an airtight lid. Typically, these are anaerobic systems that do not need oxygen to make compost. They include Bokashi Bin Systems and digesters. The Green Cone is a good example of a digester that uses a lid to keep flies away. 

Do note that a lid can be a good way to prevent the compost from becoming wet from rain, which can indirectly prevent fly infestations. As long as there is sufficient ventilation, oxygen will still get into the compost. 

Use a fly-proof mesh 

Fly Proof Mesh from Amazon, ideal for fly-proofing compost bins.

Another way to keep insects out – while allowing air in – is to use a fly-proof mesh. This is ideal if you have a smaller wooden compost bin or a bin that has ventilation holes in it. 

How to control compost flies when you have an infestation

So you already have flies, and are wondering what to do? Here’s some ideas…

Rescue the compost heap

A pile of rotting apples on top of a wet compost heap.

If you have problems with your compost heap, you can often rescue it with a bit of work.

Compost is too wet: Turn and/or mix in absorbent brown materials such as paper or sawdust. 

Compost is not heating up: Aerate. If high in brown materials, add green (high nitrogen) materials such as manure or fresh grass. Consider adding insulation, either by increasing the size, using straw around the compost or by putting the compost in an insulated bin. 

Compost is matted or compacted: Turn and add bulking agents such as sawdust.

As the compost becomes active and materials rapidly break down, the fly infestation should end!

Leaving the lid off to allow predators 

Predatory insects such as ground beetles, rove beetles, and earwigs are attracted to the moist environment and decaying organic matter in the compost bin.

By leaving the lid off, these predators have easy access to the flies and other pests that are attracted to the compost. In turn, they help to control the fly population and maintain a healthy balance in the compost ecosystem.

Use biological controls 

Close up of a nematode.

If leaving your compost bin open hasn’t worked, you might want to try using your own biological controls. 

One effective control method is using parasitic wasps, which lay their eggs inside fly pupae. When the wasp larvae hatch, they consume the fly pupae, which reduces the number of adult flies that emerge.

Another biological control option is using nematodes, which are microscopic worms that feed on fly larvae in the soil. You won’t stop the adult flies from coming, but you will stop their larvae from becoming even more flies. 


Do bear in mind that one problem with trapping flies is that you are also likely to kill or trap other beneficial decomposers. What’s more, it won’t stop more flies from coming.  

For that reason, I would only use it as a last resort

There are two options to use – traps you can buy and traps you can make. 

Fly traps you can buy

Fly Bait: The bait is placed in a trap or jar, and flies are drawn to it. Once they enter the trap, they are unable to escape. 

Fly Traps with Attractants: These traps use an attractant, such as a pheromone or a food-based lure, to lure flies into the trap. Once inside, the flies are trapped and unable to escape. Some fly traps with attractants are designed for indoor use, while others are suitable for outdoor settings.

Disposable Fly Traps: These traps come pre-filled with bait or attractant. They are usually hung, but could also be placed in the bin. Once the trap is full, it can be disposed of and replaced with a new one.

Home-made traps

Flies trapped in the bottom of a plastic bottle.

Vinegar Trap: Simply pour a small amount of apple cider vinegar into a jar or bowl and add a drop of dish soap. The vinegar will attract the flies, and the soap will break the surface tension, causing them to sink and drown.

Sticky Tape Trap: This trap is perfect for catching flying insects like flies, gnats, and fruit flies. Cut a strip of sticky tape or use adhesive tape and place it in your bin. Flies will be attracted to the tape and will become stuck to it.

Bottle Trap: This is another simple but effective trap to use in a compost bin. Cut the top off a plastic bottle and invert it so that the neck is facing downward. Push the bottle into the compost. Pour a sweet liquid like fruit juice or soda into the bottom of the bottle, and flies will be attracted to it. Once they crawl into the bottle, they will be unable to escape.

Milk Jug Trap: This trap is a also great way to recycle an old milk jug. Cut a hole in the side of the jug near the top. Make a hole in the compost, place the jug in it and fill it with a sweet liquid. Flies will be attracted to the liquid, crawl into the jug through the hole, and become trapped inside.

Flypaper Trap: You can make your own by coating strips of paper with a sticky substance like honey or corn syrup and placing it in a compost bin. 

Why it’s best to avoid using insecticides

One solution we haven’t mentioned is using insecticides. There are a few reasons for that: 

  1. They don’t address the cause of the problems. As flies both breed fast and are attracted from outside the compost bin, it’s often a very temporary solution. 
  2. Insecticides can harm beneficial microorganisms in the compost bin or heap which can help the composting solution. 
  3. It may not be a good idea to put poison in compost that will be used in your garden – especially if you are buying vegetables. 

Wrapping up 

If there’s one thing to take away from this article, it’s that the same steps you need to build a good compost will also help prevent a fly infestation. 

Prevention is also better than cure – flies breed fast, and killing them is often a short-term solution. Even if you already have a fly infestation, there are plenty of things you can do to rescue the compost heap and deter future winged visitors!

Read more

Easy Strategies to Keep Fruit Flies Away from Your Compost Bin
9 Easy Ways To Stop Compost From Smelling