The cobra is an example of "evolutionary remodelling"
Scientists have uncovered the mechanism behind the menacing "hood flare" which cobras use as a defensive display.
By measuring the electrical activity from the snakes' muscles, they found the precise group of muscles used by cobras to raise their hoods.
The researchers say that the cobra's hood evolved as its ribs were "co-opted" to be used in this visual display.
They report their findings in the Journal of Experimental Biology
Kenneth Kardong, professor of zoology from Washington State University in the US, was one of the authors of the study.
He explained that the cobra's hood was "an intriguing problem in evolutionary biology".
"In the cobra, both the [rib bones] and the muscles that work them are deployed to erect this visual display," he explained to BBC News.
"We wanted to examine the way in which the ribs were 'freed up' to rotate into this presentation position, and to understand how the muscles were able to accomplish that and return them to a relaxed position."
To do this, the researchers took measurements of electrical activity from all of the muscles in the cobra's neck.
The cobra's skeleton reveals how its ribs have been "co-opted" for display
They had to embark on some very tricky surgery to implant tiny electrodes into the snake's neck muscles, with the animal very carefully anaesthetised.
Bruce Young from the University of Massachusetts Lowell, who also took part in the study, said that doing the surgery was "the riskiest part of the study".
"You have to work around the head but the snakes are prone to waking, which can be disconcerting," he explained.
Once the electrodes were in place, the scientists waited for the snake to recover before filming and recording the muscle activity as the animal flared its neck.
They found that just eight muscles were involved in "hooding" and that they were muscles that were also present in non-hooding snakes.
"This is an example of evolution's remodelling [as] derived species emerge," said Dr Kardong. "There's been a change in the nervous system's control over these muscles."
Professor Young explained that cobras were not the only snakes to hood. "Several groups of unrelated snakes show almost identical defensive behaviour," he said. He now hopes to study how these other snakes raise their hoods.