Watching an orangutan sleep is like watching a giant, orange baby slumbering sweetly.

These huge great apes like to get into bed, and nestle down for a long and deep night’s sleep, their eyes occasionally dancing behind their eyelids, perhaps dreaming a fleeting orangutan’s dream.

Watching a baboon sleep is more like watching a small bitter paranoid person desperately trying to get some shut eye.

Sleep has only recently been acknowledged as a potentially critical factor in human evolution

They sleep badly; sitting upright, balancing on their bottoms, minds whirring, constantly fearful that something or someone is after them.

Which begs an important question: why does an orangutan sleep so soundly, whereas its primate relative, the baboon, suffers a fretful night’s rest?

The answers, scientists are learning, are rooted deep in our evolutionary history. They help explain, in part, how great apes including humans were able to evolve into the beings we are today, and also why humans routinely prefer to sleep in beds.

“Sleep has only recently been acknowledged as a potentially critical factor in human evolution,” says anthropologist David Samson of Duke University in Durham, North Carolina, in the US.

Why do both these large bodied primates differ so remarkably in their sleep behaviours?

Yet scientists have rarely studied how sleep may have affected our development as a species.

So Dr Samson and colleague Robert Shumaker of Indiana University in Bloomington, in the US, decided to do just that.

They chose two primate species to study, publishing the results in the American Journal of Physical Anthropology.

“We chose orangutans because they were a species of ape that had yet to be studied by sleep scientists,” Dr Samson told BBC Earth.

“Furthermore, they are the most distantly related great ape to humans, and therefore are an important species to generate comparative data.”

“The baboons were chosen specifically due to their being one of the largest bodied monkeys that do not use sleeping platforms. Essentially, I wanted to control for body size and ask the question: why do both these large-bodied primates differ so remarkably in their sleep behaviours?”

The scientists videoed five orangutans and 12 baboons sleeping in captivity over periods of one to four months.

They studied their sleeping positions, body movements and sleep patterns, recording the time the primates spent awake and asleep, and whether their sleep was fragmented. They also monitored brain activity, by measuring rapid eye movement (REM), or lighter sleep, versus nonrapid eye movement (NREM), or deeper sleep. In humans, REM sleep is associated with dreaming.

By every measure of sleep quality, orangutans are the ‘better’ sleepers

They confirmed that the orangutans slept for longer, and more deeply than the baboons, suggesting that all great apes do indeed sleep better than monkeys.

“We discovered that by every measure of sleep quality, orangutans are the ‘better’ sleepers; that is, compared to baboons, orangutan sleep is deeper, longer in duration, and less fragmented,” says Dr Samson.

Why they do so is even more revealing.

To date, every population of wild great ape studied builds platforms to sleep on. Gorillas, orangutans, chimps and bonobos create nesting platforms in the trees, whereas modern humans construct beds to lie on.

But every other type of primate does not sleep this way.

Gibbons, the smaller apes, do not construct sleeping platforms, nor do any large monkeys such as baboons. Most monkeys actually sleep sitting in the trees, balancing on a branch, often upright, resting upon their bottoms.

And that difference in sleeping style explains how well they sleep.

The orangutans studied liked to relax, lying down, sleeping on their front and back. “The baboons spent most of their time sleeping while sitting up in a guarded position,” says Dr Samson. When baboons rest this way, they often sit upon thick, pink patches of hard skin, called ischial callosities, which shape their buttocks.

This difference in sleeping style may have played a fundamental role in the evolution of great apes, including humans.

Sleeping platforms allowed apes with large mass to sleep securely in the trees

Around 14-18 million years ago, the common ancestor of great apes is thought to have switched from sleeping on tree branches to within specially constructed sleeping platforms.

“I don’t believe the first platform-constructing ape thought they would have a better night’s sleep,” says Dr Samson.

Instead, throughout the Miocene (an epoch lasting from 23 to 5 million years ago), apes were growing bigger. They likely started building sleeping platforms to support their size and weight.

“Sleeping platforms allowed apes with large mass to sleep securely in the trees, bypassing predators and blood sucking insects,” explains Dr Samson.

He’s conducted previous research suggesting that all primates weighing more than 30kg likely needed to build a bed in the trees, sleeping in such platforms.

And sleeping in beds confers another significant evolutionary advantage, it allows apes to sleep more deeply, getting more deep, nonrapid eye movement (NREM), sleep.

We apes seem to have innovated an effective way to sleep both securely and comfortably

“This ‘better’ sleep could have positively affected cognitive ability,” says Dr Samson, perhaps improving the consolidation of memories, for example.

“Sleep quality may be a critical difference between apes and monkeys. Monkeys likely spend more time in ‘light’ sleep due to their less comfortable, less secure, and socially dynamic sleep environments. The trade-off is that they can easily arouse from sleep when a predator is around, or a social partner is active, but the cost is that they don’t achieve the benefits of deep sleep.”

“We apes seem to have innovated an effective way to sleep both securely and comfortably.”

“From an evolutionary perspective, just as the transition from tree branches to sleeping platforms had adaptive benefits, so too did the early hominin transition from sleeping platforms to secure ground sleep."

This later transition, to sleeping on the ground, and later in beds, could have given early humans a competitive advantage over other species, he says.

Follow Matt Walker and BBC Earth on twitter.