What do snakes eat is a question with one firm rule and a lot of variety underneath it: every snake is a carnivore. There are no vegetarian snakes — none eat plants, fruit, or seeds. What changes from species to species is the prey they specialize in, and that single fact explains an enormous amount about where a snake lives, when it is active, and why it might turn up near your home. A snake is almost always in a place because that place feeds it.
Rodents are the headline prey for many of the snakes people encounter around buildings. Rat snakes, kingsnakes, bullsnakes, gopher snakes, and most rattlesnakes are rodent specialists, and they follow mice, rats, voles, and chipmunks into barns, sheds, crawl spaces, woodpiles, and gardens. This is the single most important thing to understand about snakes near a home: a rodent problem is a snake attractant. Where there are mice, there is food, and a hunting snake will keep returning to the buffet until the rodents are gone.
Plenty of snakes eat smaller or different prey. Garter snakes — among the most common backyard snakes in North America — are generalists that take earthworms, slugs, leeches, frogs, toads, tadpoles, and small fish, which is why they thrive in damp gardens and near water. Tiny species like ring-necked, brown, and worm snakes eat soft invertebrates: earthworms, slugs, soft insects, and the like. Water snakes specialize in fish and amphibians. Some snakes are remarkably specialized — certain species eat almost nothing but bird and reptile eggs, others hunt lizards, and a few, like kingsnakes, regularly eat other snakes, including venomous ones.
How snakes subdue and swallow prey shapes their diet too. Constrictors — rat snakes, kingsnakes, pythons, boas — coil around prey and tighten until circulation stops, then swallow it whole. Venomous snakes use venom to immobilize prey before swallowing. Many small and harmless snakes simply seize soft prey and swallow it alive. In every case the prey goes down whole, and a snake's flexible jaw lets it swallow animals wider than its own head. Because a single large meal can last a snake days or weeks, snakes eat far less often than mammals their size — many adults eat only every week or two, and some far less.
Diet is also the key to making a property less attractive to snakes. Since most yard snakes are there for food, the durable fix is to remove the food and the cover the prey needs: control rodents, eliminate the woodpiles, brush, tall grass, and clutter that shelter both rodents and snakes, fix standing water that draws amphibians, and seal foundation gaps. Bird feeders deserve special mention — spilled seed feeds rodents, and rodents feed snakes, so a messy feeder can indirectly invite snakes. Address the food chain and the snakes lose their reason to stay.
Diet also reframes how to think about a harmless snake you find. A rat snake or kingsnake in the yard is doing free pest control, removing the rodents you do not want and, in the kingsnake's case, even eating venomous snakes. Many people who understand what a snake is eating decide a non-venomous rodent-hunter is a neighbor worth tolerating rather than a problem to remove. The species' diet tells you what role it is playing in your yard.
If you want to know which mouth you are dealing with — a harmless rodent-eater quietly working for you or a venomous species worth a professional's attention — identify it rather than guess. SerpentID lets you photograph a snake from a safe distance and compare it against common local species, so you learn what it hunts, why it is there, and whether to simply let it work or take action. Once you know what a snake eats, you know what brought it and how to change that.

