We all have an idea about what constitutes a healthy diet: plenty of fruit and vegetables, not too much sugar, not too many saturated fats, and lots of variety.

But we also do not stick to it. Many of us stuff ourselves with sweets, junk food or sugary drinks – even though we know they are bad for us.

Plenty of animals also seem to eat rubbish. In fact they go far further than we do, often eating things we would regard as not just unhealthy, but positively disgusting or even dangerous.

But these creatures are not eating senselessly. Their strange diets have benefits, and they suggest that there can be more to food than mere nutrition.

Eat what you poo

At night, wild Japanese hares chew grasses and shrubs. By day, the hares continue feeding, but not on grasses. They eat their own poo. 

Eating one's own faeces is known as "autocoprophagy". Plenty of small and medium-sized plant-eating animals do it, but it has been most heavily studied in rabbits and hares, in particular domestic rabbits and Japanese hares. They like their faeces soft and warm, fresh from the anus, and gulp it down without chewing.

By eating their own poo, they ensure that they extract as many nutrients from their food as possible.

Sometimes the soft faeces are wrapped in a membrane that is "tough enough to be peeled off with forceps". Rabbits and hares swallow these soft capsules of poo whole. The membranes may protect the microbes within the capsules as they pass through the animals' highly acidic stomachs.

They like their faeces soft and warm, fresh from the anus, and gulp it down without chewing

Weight-for-weight, small plant-eaters like hares burn more energy than large herbivores do, so they need to reap more energy from their food. Not only do they eat their own faeces, but they do so selectively, snacking on the most nutritious bits of poo.

Autocoprophagy has probably helped rabbits and hares to thrive on difficult foods like grass and woody plants, making them the most common medium-sized plant-eating land mammals.

But they are not the only ones. Guinea pigs, chinchillas, gophers, lemmings, voles and kangaroo rats all eat their own faeces. In fact, guinea pigs die if they are deprived of poo.

Good earth

In Brazil, brightly-coloured birds called yellow-chevroned parakeets build their nests in abandoned termite mounds.

The birds scrape the mound walls with their hard bills, expanding the tight cavities to make space for their families. But occasionally, the parakeets stop scraping and instead eat bits of the mound walls.

Eating soil is called "geophagy". It is quite common among birds: in particular, many birds eat soil from clay licks. But the soil from termite mounds is quite different.

In a 2015 study, researchers compared soil from termite mound walls with soil from below the mounds.

Termite mound soil could also neutralise plant toxins

They found that the soil from termite mounds contained several times more organic matter than the ground soil. It also had more macronutrients – which the birds must eat in large quantities – such as phosphorus and potassium, but fewer micronutrients like iron and zinc – which are also essential but only in small amounts.

This suggests that yellow-chevroned parakeets get extra nutrients from termite mound dirt. This would be particularly useful when producing eggs and rearing young.

Termite mound soil could also neutralise plant toxins that pose a challenge to the fruit-eating parakeets. By consuming termite mound soil, the birds may have found an antidote for these toxins in the walls of their homes.

Our close cousins the orangutans may use a similar trick.

Orangutans mostly eat leaves and fruits, which they carefully pick among the tree tops. But when they come down from the trees and travel across the jungle floor, they occasionally eat soil. They pause, smell the soil for a couple of minutes, and eat a pinch if they find it suitable.

Many cultures embrace eating soil

In the Sungai Wain Forest Preserve on Borneo, primatologist Anne Russon of York University in Toronto, Canada has observed the orangutans eating clay. At these sites, clay is easily obtained from under the thin topsoil.

"It's so easy to crack off a small lump of drier exposed clay, or to scoop out a fingerful of damp exposed clay," says Russon. "Which is what the orangutans did – simply picked up a little bit and popped [it] in their mouth when the opportunity arose."

Orangutans are not unique in doing this: many other primates eat soil. Even among humans, many cultures embrace eating soil.

Early humans may have imitated animals' soil-eating habits, perhaps to solve issues like iron deficiency or diarrhoea, says geologist William Mahaney, who has been studying geophagy in animals and humans for 30 years.

So why are the orangutans eating soil? Might they be after an extra boost of macronutrients, or detoxification of plant chemicals, like the yellow-chevroned parakeets?

Russon collected the soils chosen by the orangutans and those immediately adjacent, and sent them to Mahaney for further analysis. The results were published in 2015.

Some insects have adopted an even more extreme diet. They eat toxic plants that offer little nutrition

Mahaney found that orangutans choose soil that contains more clay and less organic matter. Salt and calcium, which are often thought to motivate soil-eating behaviour, were only present in negligible amounts. But the soils did contain quite a lot of iron.

Orangutans may prefer clay-rich soils for the same reason that people take kaolinite pills: to alleviate diarrhoea. Leaf-eating great apes are at constant risk of diarrhea, and clay minerals can tightly bind toxins in the gastrointestinal tract and neutralise them.

Alternatively, the clay could help orangutans digest their food. Orangutans get their energy and nutrients by fermenting plant matter in their guts. The fine particles of clay could improve fermentation by keeping the foods in place for longer and retaining moisture.

Curiously, the soils the orangutans chose also had higher levels of metals called "rare earth elements". Mahaney is not sure what to make of that. "We do not really know how much could be taken up [by the orangutans] or what the effects would be," he says.

The toxin diet

Faeces and soil might look odd on a restaurant menu, but in their own way they can be nutritious. However, some insects have adopted an even more extreme diet. They eat toxic plants that offer little nutrition.

They like holes in dead wood, burrows in the ground, or even empty snail shells

Mason bees (Osmia sp.) are a dramatic example. They are a vivid black, splashed with iridescent blues and greens. Unlike the more familiar honeybees, they are solitary. They feed their larvae with nutritious pollen.

However, a few species, such as O. montana and O. subaustralis, only collect pollen from daisies and sunflowers, which all belong to a family of plants called Asteraceae. Pollen from these plants is low in protein, and bee larvae grow more slowly on this diet. Bees that have not adapted to Asteraceae would even die on a pure diet.

"At our study site, Osmia bee larvae that eat only Asteraceae pollen always take two years from egg to adult," says insect ecologist Jessica Forrest of the University of Ottawa in Ontario, Canada. "Other Osmia bees that do not eat Asteraceae pollen can emerge within the following year."

So why would O. montana and O. subaustralis raise their young on a poor diet? It may be to deter parasites from invading their nest.

Female mason bees build nests in cavities. They like holes in dead wood, burrows in the ground, or even empty snail shells.

Sapyga wasps turned away from mason bee nests if they had greasy, orange pollen on them

Within these cavities, the bee erects walls of mud and leaves to form cells. Then it deposits an egg in each cell, provisions them with pollen, and seals them. Secure inside the cells, the larvae hatch, eat the pollen and grow, and eventually chew their way out.

Unfortunately for the bees, the fresh mud walls are vulnerable to parasitic Sapyga wasps. Before the mud walls dry and harden, the wasps sneak their eggs into the mason bee's nest cells. When the wasp larvae hatch, they eat everything edible within the cell, including the mason bee's precious egg.

In the wild, almost one-third of mason bee nests are parasitised by Sapyga wasps.

However, Forrest and her colleagues noticed that Sapyga wasps turned away from mason bee nests if they had greasy, orange pollen on them. Such pollen only comes from Asteraceae, so Forrest wondered if Asteraceae pollen deterred the Sapyga wasps.

In a study published in April 2016, Forrest and her colleagues surveyed 631 wild mason bee nests. They found that Sapyga wasps infiltrated a third of the nests that did not use Asteraceae pollen, but none of the 72 nests that did.

The pollen is spikey, and those spikes might damage the wasps' innards

Next, Forrest tried to rear Sapyga larvae on different pollen diets in the lab. Of 38 Sapyga larvae reared on non-Asteraceae pollen, eight survived to the last stage – while only one of 30 survived that far on pure Asteraceae pollen.

Forrest does not yet know how Asteraceae pollen undermines the wasps' development. It might be something inside the pollen: perhaps toxins, or simply the lack of proteins and crucial amino acids. Alternatively, the pollen is spikey, and those spikes might damage the wasps' innards.

Regardless of how it works, the mason bees may be using Asteraceae pollen to make their nests less appealing to parasitic Sapyga wasps. But Forrest says this cannot be the only reason.

"Osmia bees that specialize on Asteraceae pollen do so even in places where Sapyga wasps are not present," says Forrest. This suggests mason bees eat Asteraceae pollen for reasons beyond nutrition and Sapyga parasites, "but we do not know yet".

The caterpillar's nasty flavour comes, at least in part, from its diet

While specialists like O. montana and O. subaustralis eat from a narrow set of nutritionally sub-par foods, other insects mix toxic plants into their general diet. One such omnivore is the caterpillar of the wood tiger moth (Parasemia plantaginis).

Sporting orange patches on a black body, the wood tiger moth caterpillar is conspicuous against green leaves. As in many brightly-coloured species, the caterpillar's colours are a warning to predators like birds that it tastes disgusting. The larger the orange patches, the faster predators learn to avoid the caterpillars.

The caterpillar's nasty flavour comes, at least in part, from its diet.

According to a 2015 study, the wood tiger moth caterpillar sometimes eats ribwort plantain, which contains large amounts of defensive chemicals called iridoid glycosides. The caterpillar only acquires small amounts of these chemicals from the plantain leaves, but this is enough to discourage its enemies.

These wasps hijack a luckless caterpillar and lay an egg inside it

Ants sometimes kill and eat the caterpillars. But they would not go near the mashed remains of plantain-fed caterpillars.

The same probably applies to other predators. "It is often found that what is unpalatable for ants is also unpalatable for birds," says co-author Carita Lindstedt of the University of Jyväskylä in Finland.

The plantain chemicals may also defend the caterpillars from a more insidious enemy: parasitoid wasps.

These wasps hijack a luckless caterpillar and lay an egg inside it. The egg hatches into a larva, which eats the caterpillar from inside.

But Lindstedt found that the wasps are less likely to parasitise plantain-fed caterpillars than those fed dandelions. Few new wasps actually emerge from plantain-fed caterpillars, suggesting that these caterpillars are defended against them.

Wood tiger moths grow very fast on nitrogen-rich lettuce, but survival and immunity is weak

At this point it may sound like eating plantain is a win-win for the wood tiger moth caterpillars. But in fact they pay a heavy price.

Caterpillars that eat plantain grow more slowly, and ultimately gain less weight, than those that eat dandelion. Strangely, caterpillars that incorporate higher levels of defensive chemicals also sport smaller orange warning patches, which ought to make predators more likely to eat them.

In other words, eating toxic foods is a trade-off. "Wood tiger moths grow very fast on nitrogen-rich lettuce, but survival and immunity is weak," says Lindstedt – whereas toxin-rich foods like plantain help them fend off parasites, but slow their growth. "Lettuce is fast food, but the caterpillars would need some healthy food or else they would die."

It seems a diet of rubbish really can be good for you – but only in moderation.

Join over five million BBC Earth fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "If You Only Read 6 Things This Week". A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.