It was a blood-chilling sight. The multi-headed Lernaean Hydra, a fearsome, serpent-like creature, emerged from its lair and bore down on a waiting Heracles, the son of the Greek god Zeus. But Heracles had a plan. Earlier, he had realised that the Hydra would regrow any head that was chopped off, so he had enlisted the help of his nephew Iolaus.

I'm absolutely convinced that they noticed these naturally occurring abnormalities around them

This time, when Heracles struck at the creature, Iolaus swooped in and burnt the stump of its necks with a firebrand, preventing the diabolical beast's heads from growing back. All the while the Hydra hissed and writhed, its poisonous blood and breath threatening to exterminate Greece's greatest hero. But he prevailed. The monster's final head was at last amputated and a victorious Heracles was able to progress to the third of his twelve labours.

A multi-headed beast with poisonous innards and the ability to regrow body parts – it was certainly some feat of imagination. In one telling, the Hydra has as many as 50 heads, though several depictions show it with far fewer. But where did this extraordinary idea come from? Could the Greeks have got their idea for a multi-headed serpentine ogre from nature itself?

Scientists have documented rare cases of two-headed specimens for many years. One, L E Cable, wrote during the 1940s about a two-headed pipefish embryo. He called it a "tiny monstrosity".

More recently, developmental biologist Arkhat Abzhanov at Imperial College, London, has seen many examples of two-headed creatures in his lab. With the help of a modern understanding of genetics, he has observed mutations and cellular displacements that could allow for this phenomenon. Such cases could well have inspired ancient writers of myths.

Two egotisms in the place of one

"I'm absolutely convinced that they noticed these naturally occurring abnormalities around them, and tried to explain them in some way or incorporate them into their culture," says Abzhanov.

It's true that, from time to time, two and even three-headed animals are found in the wild or in captivity. Interestingly, this phenomenon – known as polycephaly – does not seem restricted to any one class of animals. Take fish, for starters. In 2013, a two-headed bull shark foetus was discovered in the Gulf of Mexico.

The following year, a similar case was found in marine mammals when a two-headed dolphin washed up on a Turkish beach. These both appear to be examples of conjoined twins – offspring that develop from an egg that does not separate completely after fertilisation. It happens in humans as well. Often, such offspring don't just have two heads, but double sets of certain internal organs and even limbs.

One famous set of experiments showed it was actually possible to restrict fertilised eggs from splitting – and thereby instigate conjoined twins. It was carried out by a biologist called Hans Spemann in the early 20th Century. He was interested in understanding how embryos develop. He tied very young salamander embryos together with a strand of human baby hair. This, he found, could result in salamanders with two heads – two heads that fought over food for the same body. He said this was "two egotisms in the place of one."

Getting the shape and composition of a face right is a function of an organism's genes

In fact, the list of example animals is quite long – including turtles snakes and even kittens. We also know that these are not just modern day occurrences because palaeontologists have discovered fossilised two-headed embryos that date back millions of years.

As Abzhanov points out, there are various mechanisms that can result in more than one head or face. He explains that heads, as a feature on an organism's body generally, are an example of convergent evolution – when similar traits evolve separately in completely different groups of species. Animals with and without backbones both benefit from having heads, but have different ancestral lineages. Heads just seem to be useful adaptations that can arise in a wide range of organisms.

"It's actually a beneficial thing to have," explains Abzhanov. "You're heading into the new environment head-first."

That's why so many sense organs – eyes, ears, nose and mouth, for instance – are found there. Getting the shape and composition of a face right is a function of an organism's genes. And one gene that has a big impact, specifically on the width of the face, is curiously named "Sonic Hedgehog", or SHH. It's named after a series of "hedgehog" (HH) genes first described in relation to fruit flies – mutations that caused the fruit flies to be born with spiky hair-like structures, making them look like tiny hedgehogs.

 

It is vertebrates, animals with backbones, that have the SHH gene. Abzhanov explains that if the hedgehog signalling pathway is weakened during embryonic development, then the organism's head will get narrower and narrower. It will even begin to collapse in on itself in some cases, causing animals to be born with a one-eyed, cyclops-like, head. In fact, a substance known to cause this deformity in livestock such as sheep is named "cyclopamine". It's found in corn lilies, for instance, which is sometimes eaten by pregnant females.

If you take the group of cells and implant [these] on the body of a frog embryo it will have two heads

What if you instead increase the SHH signal instead, though? That leads to the opposite outcome – a head that widens until two faces are produced. "Those kind of mutants are rare, but they're reported in domestic animals and in the wild," says Abzhanov.

Technically, of course, this will only ever result in a two-faced, not two-headed specimen. For a completely separate neck and head growing from a single body, Abzhanov has observed another quirk that happens early in development.

"The head is just like any structure on the body, it needs to be triggered and [to do this] there is a group of cells in a very early embryo – what we call an organiser," he explains. In fact, it was Spemann's work with salamander embryos that eventually led to the discovery that cells could behave in this way.

"If you take the group of cells and implant [these] on the body of a frog embryo [for example] it will have two heads. That tells you that this group of cells releases a signal that tells the organism to produce a head."

This is what happens in cases of conjoined twins but Abzhanov has also noticed this happening in the lab. Sometimes an embryo will accidentally have this key group of cells transplanted onto it following an injection or incision of some kind to another embryo. Here the organiser is simply plucked up, a sort of biological stowaway, by a surgical instrument used for some other purpose and deposited elsewhere.

Researchers are getting closer to understanding why these abnormal steps in developments occur. Abzhanov notes that one factor seems to be temperature. He and his colleagues often receive fertilised eggs from chicken farms. These embryos are later inspected in the lab. But in periods of hot weather, his team has noticed strange things happening.

"If the temperature is above 30C, the batch of eggs we receive that week will have a higher rate of abnormalities – including two heads," he says.

Interestingly, this has occurred elsewhere too. One biologist for instance, found that higher water temperatures resulted in the development of a two-headed zebrafish embryo. It's not clear why these things happen, but more research is currently being done to understand how temperature can influence deformities.

 

Biology may well have inspired myth, but the opposite is also true, myth has inspired biology. Some of the Hydra's features helped to inspire the names of a group of tiny aquatic animals in 1758, named by the Swedish botanist and zoologist Carl Linnaeus. These creatures are particularly interesting because they have multiple, snake-like appendages and also have the ability to regenerate themselves – like the Hydra faced by Heracles.  

It's not so common to have two-headed salamanders

One thing to note, though, is that many two-headed organisms, like conjoined twins, do not have a very good survival rate. It's rare for them to live past the embryonic stage and even rarer still that they make it to adulthood.

A 2014 example demonstrates how the continuing development of an organism as it grows can put great stresses on multi-headed creatures. A chance occurrence – that would presumably delight Spemann – was reported by a lab at the University of Haifa in Israel – a two-headed salamander (see image below). It received a great deal of media attention but did not live very long.

"It's not so common to have two-headed salamanders," explains Leon Blaustein, who was in charge of the lab in question at the University of Haifa. "It did quite well as a larva but after the metamorphosis it just died." Salamanders are tadpoles until they metamorphose into adults – a process during which they lose their gills and some fins. The head, in particular, goes through a lot of changes. Eyes develop, tongues and teeth appear and the mouth gets broader. Perhaps these dramatic changes may have led to its untimely death – the answer is not known.

Besides the observation of real two-headed animals in the wild, the Greeks could have had other potential sources of inspiration, suggests Abzhanov. He points out that snakes have a habit of grouping together during mating seasons – forming a "mating ball".

"You can imagine seeing one 'body' and several heads," he says. "You have this multi-headed snake lying in the bushes, very dangerous looking as well." Indeed, some ancient illustrations of Hydra just happen to look quite like this.   

Polycephaly is certainly unusual, and humans are psychologically prone to be unsettled by things that they find abnormal. Such reactions could help to explain why a deformity was used to make the Hydra of Greek myths such a frightful creature.

Indeed, the story of Blaustein's two-headed salamander, like Cable's early description of a "tiny monstrosity", captures human discomfort at polycephaly. People even indulged in conspiracy theories about the case. "Things started getting out of hand because there were different groups claiming on the web that it was due to radiation," recalls Blaustein, "but we don't know why it happened."

The Hydra is far from the only monster in human mythology that bore more than one head. Another beast Heracles had to face, the twelfth of his twelve labours, was the multi-headed dog Cerberus. An ancient Japanese myth tells of Yamata no Orochi – an eight-headed snake. And there is a Slavic myth about Zmey Gorynych – a three-headed dragon.

Polycephaly, as a literary trope, suggests multiple challenges in one, something that cannot be defeated easily. It therefore makes sense that there is a whole culture of discomfort around multi-headed monsters.

There is still much to be discovered about polycephaly in animals, but given the low survival rate of two-headed organisms, both in captivity and in the wild, there's no reason to suppose that the trait will ever be more than extraordinarily rare in real life.

We can only guess at where the authors of classical myths got their ideas from. It is possible that someone, at some ancient time, stumbled on polycephalic creatures in the wild and told exaggerated stories about them. Eventually, these may have turned into the well-known legends we hear today.

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.