Part of the The Complete Guide to Flies: Identification, Prevention & Elimination guide.
Compost is one of the most valuable things a home gardener can produce — a free, living soil amendment built from kitchen and yard waste. It is also, when managed carelessly, one of the most effective fly breeding sites you can create within 10 feet of your back door. The good news is that fly problems in compost bins are almost entirely preventable, and they tell you something specific about what is going wrong with your bin management. Fix the management, and the flies disappear.
For a comprehensive overview, see our Complete Guide to Flies.
Why Flies Are Attracted to Compost
Flies locate compost through the same olfactory mechanisms they use to find any food source: volatile organic compounds released by decomposing organic matter. What attracts flies to a compost bin specifically depends on the bin's contents and management, but the primary attractants are:
- Exposed fresh food waste: Fruit peels, vegetable scraps, and especially meat or fish waste emit volatile compounds that attract house flies and blow flies immediately on exposure to air
- Fermentation odors: Partially decomposed fruit and vegetable matter produces acetic acid, alcohols, and fermentation esters that are highly attractive to fruit flies (Drosophila melanogaster)
- Protein decomposition: Meat, fish, dairy, and egg waste produce the sulfur compounds and amines that attract blow flies, which can establish large populations in a compost bin containing these materials
- Moisture: Excessively wet compost creates the anaerobic conditions that intensify fermentation odors and produce an environment ideal for fly larval development
The key insight is that the specific fly species you're seeing tells you what's wrong. Tiny fruit flies signal fermenting fruit and vegetable matter close to the surface. Large house flies indicate improperly buried food waste or a compost surface that is too accessible. Metallic blue or green blow flies in or around the bin strongly suggest meat, fish, or bone material in the compost.
Which Fly Species Infest Compost Bins
House Flies (Musca domestica)
House flies are the most common fly pest in poorly managed compost bins. They lay eggs in warm, moist organic matter and complete their life cycle in as few as 7 to 10 days under summer conditions. A single compost bin left unturned with exposed food scraps can support multiple overlapping generations of house flies, producing adult flies that then move into your home or yard.
Fruit Flies (Drosophila spp.)
Fruit flies infest compost bins containing fermenting fruit, vegetable, and sugary waste. They breed in the surface layer of the compost where fermentation is most active and where the wet-to-dry gradient creates a suitable egg-laying environment. Compost fruit fly problems are often connected to indoor fruit fly problems — the same population forages between your countertop and the outdoor bin.
Blow Flies (Calliphoridae)
Blue bottle flies, green bottle flies, and related species are attracted to compost that contains meat, fish, eggs, or bones. These materials should ideally not go into a standard backyard compost bin, both because of fly attraction and because they decompose slowly and can create odor problems. When blow flies appear at your compost, check recent additions for protein waste.
Black Soldier Flies (Hermetia illucens) — The Exception
Black soldier flies deserve special mention because they are frequently mistaken for a pest when they are actually a highly beneficial compost inhabitant. Adult black soldier flies are large (15–20 mm), dark, and wasp-like in appearance, with two translucent patches on the abdomen that distinguish them from other flies.
Their larvae are extraordinary composters — voracious, efficient, and capable of breaking down food waste including meat, dairy, and citrus that house flies would exploit as a pest breeding site. Black soldier fly larvae actually suppress house fly populations in compost because they outcompete house fly larvae for resources and produce compounds that deter house fly oviposition.
If you have black soldier fly larvae in your compost bin, this is an asset, not a problem. Adult black soldier flies do not bite, do not visit human food, and are not found in homes. The larvae reduce volume of organic waste rapidly and produce high-protein frass (excrement) that is an excellent soil amendment.
| Species | Pest or Beneficial? | Signs | Response |
|---|---|---|---|
| House fly (Musca domestica) | Pest | White maggots near surface, adult flies hovering | Improve burial, add dry browns, manage moisture |
| Fruit fly (Drosophila) | Pest | Tiny flies around surface, especially near fruit scraps | Bury food waste, cover with compost or soil |
| Blow fly (Calliphoridae) | Pest | Metallic adults near bin, larger maggots | Remove protein waste, use enclosed bin |
| Black soldier fly (Hermetia illucens) | Beneficial | Large, dark larvae in clumps, rapid waste breakdown | Leave them — they are helping |

Preventing Fly Problems in Compost
The vast majority of compost fly problems are preventable with consistent bin management. These practices address the conditions that allow flies to breed rather than trying to kill adult flies after the fact.
Bury Food Waste
The single most effective fly prevention measure is burying fresh food additions under at least 4 to 6 inches of existing compost or dry carbon material (leaves, straw, shredded paper, cardboard). Flies oviposit on or near the surface of accessible organic matter — if food scraps are buried, flies cannot reach them to lay eggs.
Create a pocket in the center or edge of the compost mass, deposit food waste, and cover immediately. Do not leave food scraps sitting on the surface overnight or between bin visits.
Maintain the Carbon-to-Nitrogen Balance
The classic "greens and browns" ratio — roughly 1 part nitrogen-rich materials (food scraps, fresh grass) to 3 parts carbon-rich materials (dry leaves, cardboard, straw) by volume — creates conditions unfavorable for fly breeding. An excess of nitrogen-rich "greens" without sufficient carbon creates the wet, smelly, anaerobic surface conditions that house flies and fruit flies exploit.
When your compost smells bad and flies are present, the solution is almost always to add more dry, carbon-rich material and turn the pile to introduce oxygen.
Turn Regularly
Turning the compost weekly or biweekly during active fly season serves multiple functions: it buries any surface-exposed food waste, disrupts fly egg-laying and early larval stages, introduces oxygen that favors aerobic decomposition over anaerobic fermentation, and generates the internal heat (140°F or higher in a properly managed hot compost pile) that kills fly eggs and larvae.
Use an Enclosed Bin
Open-sided compost piles and bins without tight-fitting lids provide easy fly access. Enclosed bins — particularly tumbler-style composters with sealed chambers — dramatically reduce fly access. A tight-fitting lid prevents adult flies from entering to lay eggs; without egg-laying access, no breeding population establishes in the bin.
Manage Moisture
Compost should feel like a wrung-out sponge — moist but not dripping. Excessively wet compost intensifies fermentation odors and creates the conditions in which fly larvae thrive. If your bin is too wet, add dry carbon material (shredded leaves, cardboard, wood chips) and turn to improve drainage and airflow.
Avoid Problem Materials
Certain materials create fly problems regardless of otherwise good bin management:
- Meat, fish, and bones: Avoid in standard backyard compost; use only in a black soldier fly bin or a tumbler with very secure lid
- Dairy products: Similar issues to meat — high fly attraction and slow decomposition
- Cooked food with oil or sauces: More attractive to house flies than raw vegetable waste, and often wetter
- Pet feces: Never compost dog or cat feces; it attracts flies and contains pathogens
Fixing an Active Fly Infestation in Your Compost Bin
If house flies or fruit flies are already breeding in your compost, take these steps in sequence:
- Stop adding fresh food waste temporarily until the active infestation is under control
- Turn the compost thoroughly, burying all exposed food waste and disrupting maggot masses. If you find maggots (white, legless larvae), this is house fly breeding in progress — turn the pile, cover with a thick layer of dry leaves or cardboard, and the deprived larvae will quickly die or fail to complete development
- Add dry carbon material generously to shift the moisture and carbon-to-nitrogen balance
- Place fly traps near the bin to reduce adult fly populations around the area — baited bag traps positioned 10 to 20 feet from the bin draw flies away. Our DIY fly traps guide covers simple homemade trap options
- Secure the lid and inspect it for gaps where flies are entering
- Consider relocating the bin if it is positioned in full sun against a fence or wall that retains heat — very hot, wet bin conditions accelerate fermentation and fly attraction
For flies that have followed the compost source indoors, our how to get rid of flies article covers the indoor management component, and our article on flies in the garage covers situations where compost bins are stored in attached garage spaces.
In my 15 years of pest management in central Florida, the compost fly calls I receive almost always involve one of two scenarios: someone composting meat or fish scraps in an open bin, or a household that has gotten away with good compost management for years until a hotter summer changes the fermentation rate in the bin and suddenly they have a problem. The fix is always the same — more carbon, more turning, better burial of fresh waste. The biology of the bin determines the fly pressure.
How to Identify
Identifying the fly species in your compost bin determines whether you have a pest problem or a beneficial presence. House fly maggots are white, legless, and taper to a narrow head end, reaching 10 to 12 mm at full development; they appear near the surface of decomposing material when food scraps are accessible to egg-laying adults. Adult house flies (dull gray, 6 to 7 mm) hovering and landing on the bin surface signal active breeding. Fruit fly adults are tiny (3 to 4 mm) with red eyes, hovering in slow looping patterns near fermenting fruit and vegetable material on the bin surface. Blow fly maggots are larger (up to 18 mm), cream-white; adult blow flies are metallic blue or green (8 to 14 mm) and indicate protein waste such as meat or fish has been added to the bin. Black soldier fly larvae are dark brown to black, heavily armored, and larger (up to 25 mm), found in the deeper active sections of the compost. Finding house fly or blow fly maggots near the surface signals a management problem requiring immediate action; finding black soldier fly larvae indicates beneficial decomposition activity that should be left undisturbed.
Risk and Severity
The risk from compost bin flies depends on species, proximity to living spaces, and whether populations are moving beyond the bin. House flies breeding in compost represent a concrete food safety risk: adults foraging between the compost and kitchen surfaces, food preparation areas, and outdoor eating spaces mechanically transfer Salmonella, E. coli, and Campylobacter throughout the warm season. The CDC identifies house flies as significant mechanical vectors of foodborne pathogens, and a heavily infested bin within 10 to 15 feet of a kitchen door creates sustained cross-contamination pathways. Blow flies in compost carry a higher pathogen load than house flies because they also frequent feces and carrion. A compost bin actively producing visible adult house fly populations at any level represents a food safety concern warranting immediate corrective action. Fruit flies in compost are the lowest health risk but indicate fermentation conditions that, if not corrected, will attract house flies to the same material.
Main Causes
Indoor flies activity is driven by accessible breeding material and warmth. House flies and blow flies breed in garbage, pet waste, compost, and dead animals; fruit flies breed in overripe produce, drain biofilm, fermenting liquids, and unrinsed recycling; drain flies breed in the gelatinous film inside infrequently used drains; phorid flies breed in broken sewer lines and decomposing material under slabs. Adults find their way inside through torn screens, gaps around doors, vents, and any opening to the outside. Warm weather accelerates the entire life cycle, and a sustained population always points to an unaddressed source either inside the structure or close enough that adults keep arriving in volume.
Solutions and Actions
Effective fly control requires locating and eliminating the breeding source — adult-only treatments produce only temporary relief. For house flies: remove and seal garbage, clean pet waste daily, manage compost properly, and check for dead animals in wall voids or attics if blow flies are present. For fruit flies: discard overripe produce, clean drains with enzymatic cleaner weekly, rinse recycling, and empty kitchen compost containers daily. For drain flies: brush drain walls thoroughly and treat with enzymatic drain cleaner weekly for at least three weeks. For phorid flies: investigate for broken sewer lines or moisture intrusion under slabs. Adult control through sticky cards, UV light traps, and targeted residual sprays supplements but never substitutes for source elimination.
Prevention
Prevention combines source elimination with exclusion. Keep all kitchen garbage in sealed bins and empty daily during warm months. Refrigerate ripening produce, rinse all recyclables before storing, and run garbage disposals briefly each day. Clean drains weekly with enzymatic drain cleaner during fly season, and brush drain walls with a flexible drain brush quarterly to remove biofilm. Remove pet waste from the yard daily. Manage compost with a proper carbon-to-nitrogen ratio and bury food scraps under brown material. Install and maintain tight-fitting window and door screens, repair tears promptly, and add door sweeps to exterior doors. Inspect the structure annually for dead-animal indicators (sudden blow fly activity) and resolve any wildlife exclusion issues that could lead to carcasses in wall voids.
Frequently Asked Questions
Are maggots in compost always a problem?
It depends on the species. House fly maggots (white, tapered, 8–12 mm at maturity) are a pest concern — they indicate exposed food waste accessible to ovipositing house flies, and the adult flies that emerge will move into your home and yard. Black soldier fly larvae (dark, armored, up to 25 mm) are beneficial and should be left in place. They actually suppress house fly breeding and break down waste far more efficiently.
Can I compost citrus peels and onion scraps — do they repel flies?
Citrus peels and onion scraps do not meaningfully repel flies when composted. The repellent compounds in these materials are concentrated in fresh, volatile form; once the material begins decomposing in a moist environment, the fermentation odors produced are at least as attractive to flies as the putative repellent compounds. Bury citrus and onion additions like any other food waste.
Should I add lime or baking soda to my compost to control flies?
A small amount of agricultural lime (calcium carbonate) can raise the pH of overly acidic, wet compost and temporarily reduce fermentation odors. It is not a fly control measure on its own, but it can be a useful adjunct to improving the carbon-to-nitrogen ratio. Baking soda provides a similar temporary effect. Neither kills fly eggs or larvae and neither is a substitute for proper bin management.
How far away from the house should a compost bin be placed?
At minimum, 10 to 15 feet from exterior doors and windows, and positioned so that prevailing winds carry any odor plume away from the house rather than toward it. Bins placed directly against the foundation or immediately adjacent to kitchen door thresholds significantly increase the likelihood that flies breeding in the compost will move indoors.
Sources: EPA — Composting and Yard Waste Management | UC IPM — Fly Management
Continue reading:
The Complete Guide to Flies: Identification, Prevention & Elimination →Sources & Further Reading
- House Flies — Pest Notes — University of California Statewide IPM Program
- Fruit Flies in the Home — Penn State Extension
- Controlling Pests Safely — U.S. Environmental Protection Agency