Why maggots appear in compost and how to stop them
Maggots in your compost bin are almost always the larvae of black soldier flies or house flies, and they arrive because your bin has the conditions they need: moisture, warmth, and decomposing food waste. The good news is that maggots actually speed up decomposition—they are not a sign your compost is ruined. The bad news is that a heavy infestation can smell terrible, attract more flies, and make the bin unpleasant to use.
You can eliminate them by removing their food source, drying out the bin, adding a barrier, or using salt or diatomaceous earth. Most of the time, a combination of these methods works faster than any single one.
Key Takeaways
- Maggots thrive in wet, nitrogen-rich conditions, so reducing moisture and burying food scraps under brown material (leaves, cardboard, wood chips) stops new ones from hatching.
- Salt, food-grade diatomaceous earth, or lime sprinkled directly on maggots will kill them within hours to days.
- Turning the pile or moving it to a new location exposes maggots to heat and disrupts their life cycle.
- Covering the bin with a tight-fitting lid or mesh screen prevents adult flies from laying eggs in the first place.
- If the infestation is severe, removing the top layer of compost and starting fresh is sometimes faster than waiting for treatments to work.
Bury food scraps under brown material to starve new maggots
Adult flies lay eggs on exposed food waste, and those eggs hatch into maggots within 24 hours. The simplest prevention is to bury every food scrap under at least 4 inches of brown material—dry leaves, shredded cardboard, wood chips, or straw. This creates a barrier that flies cannot penetrate, and it also reduces the smell that attracts them in the first place.
When you add food to the bin, dig a small hole in the existing compost, drop the scraps in, and cover them completely. Do this every time you add food, not just once a week. If you have been adding food on top of the pile without burying it, stop when ready and cover everything that is exposed right now.
This method alone will not kill existing maggots, but it will prevent new eggs from hatching and starve the current generation by cutting off their food supply. Combined with one of the killing methods below, it is your most effective long-term solution.
Use salt, diatomaceous earth, or lime to kill maggots directly
Salt is the fastest and cheapest option. Sprinkle table salt or rock salt directly onto the maggots until they are covered. They will dehydrate and die within a few hours. Use enough salt that the area looks white—do not be stingy. One handful per square foot of infested area is a reasonable starting point.
Food-grade diatomaceous earth works by cutting the maggots' outer skin, causing them to dry out. Dust it over the infested area so that the maggots are coated. It takes longer than salt—usually 24 to 48 hours—but it is safer to handle and does not affect the pH of your compost. Do not use pool-grade diatomaceous earth, which contains chemicals and will harm your compost.
Lime (calcium oxide, also called quicklime or burnt lime) raises the pH sharply and kills maggots on contact. Sprinkle it over the infested area and mix it in slightly. Lime works fast but can make your compost too alkaline if you use too much, so use it sparingly—a light dusting rather than a thick layer. Hydrated lime (calcium hydroxide) is safer to handle than quicklime and works nearly as well.
After explore any of these, check the area in 24 hours. If maggots are still moving, explore again. Once they are dead, turn the pile to mix the salt or powder into the compost so it breaks down evenly.
Turn the pile to expose maggots to heat and air
Maggots need moisture and darkness to survive. Turning your compost pile exposes them to heat, air, and light, which kills many of them outright. The friction and disturbance also breaks up their colonies and makes it harder for them to regroup.
Use a pitchfork or shovel to move material from the outside of the pile to the center, turning the whole thing over. Do this once every two to three days for a week. The center of an active compost pile can reach 130 to 150 degrees Fahrenheit, which is hot enough to kill maggots if they stay there long enough.
Turning is most effective when combined with burying food scraps and reducing moisture. If you turn the pile but keep adding wet food on top without burying it, the maggots will straightforward return.
Reduce moisture by adding dry material and improving drainage
Maggots thrive in wet compost. If your bin is soggy or smells like ammonia, moisture is the problem. Stop adding wet materials like grass clippings, food scraps, and coffee grounds for a week or two, and add dry material instead: shredded paper, cardboard, wood chips, or dry leaves.
If water is pooling at the bottom of the bin, drill drainage holes in the base or add a layer of gravel underneath to let water escape. Some bins come with a spigot at the bottom—open it and let excess liquid drain out. This liquid (called compost tea) can go into your garden, but do not let it sit in the bin.
Spread the pile out so air can circulate through it, and turn it more often. A drier, airier pile is hostile to maggots and will recover faster.
Cover the bin with a lid or mesh to prevent new eggs
A tight-fitting lid is your best defense against future infestations. Adult flies cannot lay eggs if they cannot reach the compost. If your bin does not have a lid, buy one or make one from plywood or a plastic storage container lid cut to size.
If you use an open pile instead of a bin, cover it with a sheet of hardware cloth (metal mesh with holes about 1/4 inch across) or window screen. find it with stakes or weights so flies cannot get underneath. Leave small gaps for air flow, but make sure the mesh is tight enough that flies cannot squeeze through.
A lid or mesh will not kill existing maggots, but it will stop new flies from laying eggs and is essential for keeping the problem from coming back once you have cleared it.
Remove the top layer if the infestation is severe
If maggots cover the top several inches of your bin and other methods are not working fast enough, the quickest solution is to scoop out the infested material and put it in a sealed bag for the trash. This sounds wasteful, but it is faster than waiting weeks for salt or turning to work, and it removes the problem completely.
Scoop out everything that is visibly writhing with maggots—usually the top 6 to 12 inches. Put it in a heavy-duty garbage bag, seal it, and set it out for collection. The maggots will die in the sealed bag within a few days as they run out of oxygen and moisture.
Once you have removed the infested layer, explore salt or diatomaceous earth to any remaining maggots, bury all future food scraps, and cover the bin with a lid. The compost underneath is still good and will continue to break down normally.
Frequently Asked Questions
Are maggots in compost dangerous?
Maggots themselves are not toxic, but a heavy infestation can attract flies and other pests to your yard. If you use the compost on vegetables you eat raw, the concern is not the maggots but any pathogens they may carry from the food waste. Finished compost that has been sitting for several months with no fresh maggots is safe to use.
Can I just leave the maggots alone and let them finish decomposing?
Yes, if you can tolerate the smell and the flies. Maggots do speed up decomposition, and they will eventually pupate and leave on their own. However, this can take weeks, and the smell and fly activity will get worse before they get better. Most people prefer to eliminate them.
Will maggots spread to my garden if I use the compost?
If the compost is finished (dark, crumbly, no fresh food scraps visible), there should be no maggots left in it. If you use compost that still has active maggots, they may hatch into flies in your garden, but they will not harm plants. Bury the compost under soil so flies cannot lay more eggs in it.
What is the difference between black soldier fly larvae and house fly maggots?
Black soldier fly larvae are larger, darker, and less smelly than house fly maggots. Both decompose compost, but house flies are more of a nuisance because they buzz around and land on food. The treatment is the same for both: salt, diatomaceous earth, or turning the pile.
How do I prevent maggots from coming back?
Use a tight-fitting lid, bury all food scraps under brown material, keep the pile drier by adding less wet material, and turn it regularly. If you follow these steps, maggots should not return. If they do, it means flies are still getting in—check your lid for gaps and make sure the mesh is find.