The short answer
- Leave out meat, fish, bones, dairy, and fats, oils and grease. They attract animals, and backyard piles generally don't get hot enough to break them down.[1][3]
- Bury food scraps in the pile and cover them with browns such as dried leaves, straw, shredded paper or wood chips, so rodents and flies can't get at them.[3][1][2]
- Keep the pile moist and turn it regularly; rats like a dry, undisturbed pile for nesting.[2]
- Use a bin with a securely fastened lid, and a floor if needed, with no holes or gaps larger than 1/4 inch. If rats dig under or gnaw in, add strong 1/4-inch wire mesh under and around it.[1][2]
- Freeze kitchen scraps before adding them to stop fruit flies; their eggs can't survive freezing.[3]
- Raccoons, skunks and opossums come for the same food. Keep table scraps out of open piles and put compost that gets food scraps in a bin with a locking lid.[9][10]
Pests that visit compost
What draws pests to compost
Rats and other omnivorous rodents are drawn by the smell of food, especially meat, fat and bones. Rats may also see a compost pile as an ideal nesting spot, especially if it's dry and undisturbed.[3][2]
EPA says a home compost pile that's well constructed and properly maintained shouldn't attract pests or rodents, though Washington State University Extension in Whatcom County cautions that it's almost impossible to rat-proof compost completely.[1][2]
UC IPM's rat guide says rats occasionally burrow beneath or around compost piles, particularly when people add meat, fish, eggs or eggshells, and it lists burrows under a compost pile among the signs that rats are around.[4]
Not every creature in the bin is a problem. Worms, slugs, earwigs and other crawling invertebrates mean the pile is a thriving habitat, and Cornell Cooperative Extension of Tompkins County says there's nothing wrong when you see them.[3]
What to leave out
- Meat, fish and bones; cheese and other dairy products; and fats, oils and grease. EPA marks these as foods that can attract animals, and backyard piles generally don't reach temperatures high enough to fully break them down. Commercial composting facilities may accept them.[1][3]
- Cooked food beyond small amounts; EPA says small amounts are fine.[1]
- Pet waste and cat litter, since household pets can carry disease organisms.[1][3]
- Diseased and pest-infested plants, and weeds that have gone to seed.[1][3]
- Treated or painted wood, and plants or grass treated with herbicide.[1][3]
- Animal products that are fine to add: hair, fur, manure from plant-eating animals, and dried, crushed eggshells.[3]
- Eggshells are where the sources part ways. Cornell Cooperative Extension of Tompkins County allows dried, crushed eggshells, but UC IPM names eggs and eggshells along with meat and fish as additions that draw burrowing rats, and the Internet Center for Wildlife Damage Management (ICWDM) says to keep eggs out of compost to avoid attracting raccoons, opossums and skunks. If rats or raccoons are already visiting, leave them out.[3][4][8]
Managing the pile
Bury food scraps in the pile and keep them covered with a layer of browns such as dried leaves, straw, shredded paper or wood chips. If rodents and flies can't find the food, they're likely to look elsewhere.[3][1][2]
EPA gives a depth: always cover food scraps with four to eight inches of dry leaves or other browns. Until scraps go out, EPA suggests holding them in a closed container on the counter, under the sink, or in the fridge or freezer.[1]
Keep the mix balanced. EPA suggests two to three parts carbon-rich browns to one part nitrogen-rich greens; Cornell Cooperative Extension of Tompkins County uses about 3 parts browns to 1 part greens by volume, which keeps greens from turning smelly.[1][3]
Keep the pile moist and turn it regularly, which makes it less attractive to nesting rats.[2]
For moisture, EPA describes the target as the consistency of a wrung-out sponge, and says to add enough browns and turn the compost occasionally to keep air moving. A pile that smells bad may be too wet or short of air; adding browns and turning it helps.[1]
A well-maintained backyard pile can reach 130 to 160 degrees F, and high temperatures help reduce pathogens and weed seeds. A pile about 3 feet by 3 feet is the minimum size that really heats up.[1][3]
Rodent-resistant bins
Use an enclosed bin for tempting kitchen waste such as fruit peelings, and keep an open pile only for less tempting yard waste like grass clippings.[2]
Keep a lid on the bin and fasten it securely. A rodent-resistant bin has a solid top, bottom and sides except for small vent holes, and EPA says there should be no holes or gaps larger than 1/4 inch.[2][3][1]
If rats burrow under a bin, stand it on strong 1/4-inch wire mesh. If they've gnawed into a plastic bin, reinforce all sides, the top and the bottom with the same mesh, and if rodents keep coming, cover the vent holes with heavy wire mesh or hardware cloth.[2][3]
UC IPM recommends rigid plastic or metal containers with tight-fitting lids for compost, and warns that rats can gnaw through plastic, which is why the mesh lining matters on a plastic bin.[4][2]
The 1/4-inch limit is about mice as well as rats: CDC says a mouse can fit through a hole the width of a pencil, about 1/4 inch.[5][1]
Location matters too. In its advice on keeping rodents away from the house, CDC says to keep compost bins at least 100 feet from your house.[5]
Watch for signs of rats around the bin. Washington State University Extension notes that you can stop rat activity before it becomes a major problem if you know the signs; our rodent pages cover them, along with trapping.[2]
Raccoons, skunks and opossums
Rats aren't the only visitors. UC IPM says raccoons in towns scavenge from garbage cans and compost piles, and ICWDM says meat, eggs, fats or oils in a compost pile can draw raccoons, opossums, skunks and other scavengers, so it recommends using only plant and vegetable matter.[7][8]
For skunks, UC IPM says food items and table scraps shouldn't go into compost bins, and to use a hot rather than a cold composting method. For opossums, ICWDM says to keep compost that receives food scraps in a container with a locking lid.[9][10]
The same steps that keep rats out work here: lids that latch, no animal products in the pile, and no pet food or fallen fruit left out nearby. Our raccoon, skunk and opossum guides cover the rest of the yard.[8][9][10]
Fruit flies, slugs and the kitchen scrap pail
Fruit fly eggs often ride home from the store on the skins of fruit and vegetables, especially tropical ones. Freezing food scraps before they go into the compost kills the eggs, and keeping scraps covered with browns stops flies from feeding or laying eggs on them.[3]
The kitchen pail can be the source as well as the bin. The University of Kentucky says fruit flies lay eggs on fermenting food and can breed in trash containers and any moist film of fermenting material, and the whole life cycle can take about a week. Kentucky notes that even a recycling bin that's never emptied or cleaned can breed thousands of them, so empty and rinse the scrap container often.[6]
For flies already in the kitchen, Kentucky suggests a jar trap: a paper funnel set in a jar baited with a few ounces of cider vinegar. Cornell Cooperative Extension of Tompkins County also suggests a fruit fly trap.[6][3]
If slugs from the compost are moving into a nearby garden bed, the barriers used in the garden, such as metal flashing, can go around the bin.[3]
Big maggots in the bin: soldier fly larvae
Large, flattened, dark brown maggots in a bin composter are often black soldier fly larvae (Hermetia illucens). Oregon State University Extension says they won't harm you or the compost and help break down plant and animal tissue, and Texas A&M AgriLife says both larvae and adults are harmless and the larvae are frequently found in compost piles.[11][12]
Young larvae are gray-white, segmented, about 1 inch long and very active; mature ones turn dark brown, flattened and tough-skinned, with no legs. Adults are about 5/8 inch long and black with smoky wings, and Oregon State says they are often mistaken for black wasps but don't bite or carry disease.[11]
- To keep their numbers down, Oregon State says to bury kitchen waste well and cover it with 2 to 4 inches of dry, absorbent material.[11]
- If larvae become abundant, turn the pile, mix in dry material and let it heat up; Oregon State says the larvae can't survive above 113 degrees F.[11]
- Cover holes in the bin with window screen attached with waterproof caulk to keep egg-laying adults out.[11]
- Texas A&M says poorly maintained compost piles can be breeding sites, and that wandering full-grown larvae may travel several yards. They're harmless and can be picked up and discarded; the fix is the breeding source.[12]
- In worm bins, Oregon State suggests burying food scraps deeply in the bedding; soldier fly larvae may eat surface scraps but won't harm the worms or their eggs.[11]
Common questions
- Can I compost meat if I bury it deep in the pile?
- Not in a backyard pile. EPA lists meat, fish, bones, dairy and greasy foods among the things to keep out, both because they attract animals and because backyard piles generally don't get hot enough to break them down.[1]
- Will a closed bin keep rats out?
- It helps, but it's almost impossible to rat-proof compost completely. Fasten the lid, leave no gaps over 1/4 inch, and add strong 1/4-inch wire mesh under or around the bin if rats dig or gnaw in.[2][1]
- Are the bugs and worms in my compost a problem?
- No. Worms, slugs, earwigs and other crawling invertebrates mean the compost is a thriving habitat. Fruit flies are the nuisance to manage, by freezing scraps first and keeping them covered.[3]
- What are the big brown maggots in my compost bin?
- Usually black soldier fly larvae. Oregon State University Extension and Texas A&M AgriLife both describe them as harmless decomposers. Bury scraps, add dry material and let the pile heat up if there are too many.[11][12]
- How far from the house should a compost bin be?
- CDC's rodent advice is to keep compost bins at least 100 feet from your house.[5]
Photo credits
- Norway Rat: petehawkins, public domain (CC0), via iNaturalist
- House Mouse: (c) Carrie Seltzer, some rights reserved (CC BY) — via iNaturalist, CC BY 4.0
- Raccoon: (c) Steven Bodzin, some rights reserved (CC BY) — via iNaturalist, CC BY 4.0
- Virginia opossum: (c) Millie Basden, some rights reserved (CC BY) — via iNaturalist, CC BY 4.0
- Fruit Fly: Jesse Rorabaugh, public domain (CC0), via iNaturalist
- Black Soldier Fly: (c) Peter Chen 2.0, some rights reserved (CC BY) — via iNaturalist, CC BY 4.0
- Snails and Slugs: (c) zebedeugalinha, some rights reserved (CC BY) — via iNaturalist, CC BY 4.0
Sources
- U.S. Environmental Protection Agency, “Composting At Home.” www.epa.gov/recycle/composting-home (accessed 2026-11-10)
- Washington State University Extension, Whatcom County, “Rats in Compost.” extension.wsu.edu/whatcom/hg/rats-in-compost/ (accessed 2026-11-10)
- Cornell Cooperative Extension of Tompkins County, Compost Education Program, “Don't Panic! Troubleshooting Your Compost Pile.” dlc.cce.cornell.edu/pluginfile.php/376512/mod_resource/content/1/Dont%20Panic%2C%20Troubleshoot%20your%20Compost%20Pile%20-%20CCE%20Tompkins%20County.pdf (accessed 2026-11-10)
- University of California Statewide IPM Program, “Pest Notes: Rats, Publication 74106.” ipm.ucanr.edu/legacy_assets/PDF/PESTNOTES/pnrats.pdf (accessed 2026-11-10)
- Centers for Disease Control and Prevention, “How to Seal Up to Prevent Rodents.” www.cdc.gov/healthy-pets/rodent-control/seal-up.html (accessed 2026-11-10)
- University of Kentucky Entomology, “ENTFACT-621: Fruit Flies.” entomology.mgcafe.uky.edu/ef621 (accessed 2026-11-10)
- University of California Statewide IPM Program, “Raccoons (Pest Notes, Home and Landscape).” ipm.ucanr.edu/home-and-landscape/raccoons/ (accessed 2026-11-10)
- Internet Center for Wildlife Damage Management, “Raccoon Damage Prevention and Control Methods.” icwdm.org/species/other-mammals/raccoons/raccoon-damage-prevention-and-control-methods/ (accessed 2026-11-10)
- University of California Statewide IPM Program, “Skunks (Pest Notes, Home and Landscape).” ipm.ucanr.edu/home-and-landscape/skunks/ (accessed 2026-11-10)
- Internet Center for Wildlife Damage Management, “Opossum Damage Prevention and Control Methods.” icwdm.org/species/other-mammals/opossums/opossum-damage-prevention-and-control-methods/ (accessed 2026-11-10)
- Oregon State University Extension Service, “Soldier fly larvae: Beneficial compost helpers.” extension.oregonstate.edu/news/soldier-fly-larvae-beneficial-compost-helpers (accessed 2026-11-10)
- Texas A&M AgriLife Extension Service, “Soldier Flies (ENT-2005, Insects in the City).” citybugs.tamu.edu/factsheets/household/flies-house/ent-2005/ (accessed 2026-11-10)