Groucho Marx once joked , “Anything that can’t be done in bed isn’t worth doing at all.” You might think he was referring to sleeping and sex. But humans, at one time or another, have done just about everything in bed.

And yet, despite the fact that we spend one-third of our lives in bed, they’re more of an afterthought. I certainly didn’t think much about beds until I found myself talking about their history with the executives of a mattress company. These humble artifacts, I learned, had a big story to tell—one that’s 77,000 years old. That’s when, according to archaeologist Lynn Wadley, our early African ancestors started to sleep in hollows dug out of cave floors—the first beds. They wrapped themselves in insect-repelling grasses to avoid bed bugs as persistent as those of today’s seedy motels.

Much about our beds has remained unchanged for centuries. But one aspect of the bed has undergone a dramatic shift. Today, we usually sleep in bedrooms with the door shut firmly behind us. They’re the ultimate realm of privacy. No one else is allowed in them, aside from a spouse or lover. But as I show in my forthcoming book, What We Did in Bed, it wasn’t always this way.

Beds full of “buck and babble”

The structure of the bed has remained remarkably consistent: We know that raised frames with mattresses were being used in Malta and Egypt by 3000 B.C., which means that people have been using them for over 5,000 years. Early Egyptian beds were little more than rectangular wooden frames with legs and leather or fabric sleeping platforms. The upper end was often angled slightly upwards. Grass, hay, and straw stuffed into sacks or cloth bags served as a scratchy mattress for centuries.

But one thing that has changed is who has occupied the bed. For most of human history, people thought nothing of crowding family members or friends into the same bed.

The 17th-century diarist Samuel Pepys often slept with male friends and rated their conversation skills. One of his favorites was the “merry Mr. Creed,” who provided “excellent company.” In September 1776, John Adams and Benjamin Franklin famously shared a bed in a New Jersey inn with only one small window. Adams kept it shut, but Franklin wanted it open, complaining that he would suffocate without fresh air. Adams won the battle.

Travelers often slept with strangers. In China and Mongolia, kangs—heated stone platforms—were used in inns as early as 5000 B.C. Guests supplied the bedding and slept with fellow tourists.