A few hundred years ago, fairy tale auteurs like the Brothers Grimm, Hans Christian Andersen and Charles Perrault helped bring magical tales of princesses, evil ogres, dark forests, weird spells and thwarted love into the storybooks—and to the bedsides—of children, everywhere. But how old are the tales they transcribed? A new study suggests that their origins go all the way back to prehistory.

In a new study published in the journal Royal Society Open Science, a folklorist and anthropologist say that stories like Rumpelstiltskin and Jack and the Beanstalk are much older than originally thought. Instead of dating from the 1500s, the researchers say that some of these classic stories are 4,000 and 5,000 years old, respectively. This contradicts previous speculation that story collectors like the Brothers Grimm were relaying tales that were only a few hundred years old.

It turns out that it’s pretty hard to figure out how old fairy tales are using simple historical data. Since the tales were passed down orally, they can be almost impossible to unwind using a historian or anthropologist’s traditional toolbox. So the team borrowed from biology, instead, using a technique called phylogenetic analysis. Usually, phylogenetic analysis is used to show how organisms evolved. In this case, researchers used strategies created by evolutionary biologists to trace the roots of 275 fairy tales through complex trees of language, population and culture.

Using the Aarne-Thompson-Uther Classification of Folk Tales, a kind of über index that breaks fairy tales down into groups like “the obstinate wife learns to obey” and “partnership between man and ogre,” the team tracked the presence of the tales in 50 Indo-European language-speaking populations. They were able to find the ancestries of 76 tales, tracking them backward using language trees.

As they tracked, they found evidence that some tales were actually based in other stories. More than a quarter of the stories turned out to have ancient roots—Jack and the Beanstalk was traced back to the split between Western and Eastern Indo-European languages more than 5,000 years ago and a tale called The Smith and the Devil appears to be more than 6,000 years old.

The findings might confirm the long-disregarded theory of fairy tale writer Wilhelm Grimm, who thought that all Indo-European cultures shared common tales. But not everyone is certain that the study proves fairy tales are that old. As Chris Samoray writes for Science News, other folklorists are finding fault with the study’s insistence that The Smith and the Devil dates back to the Bronze Age—a time before a word for “metalsmith” is thought to have existed.

Are the days of using historical records and written clues to learn more about a culture’s oral history numbered? No way, says the research team. “Of course, this does not diminish the value of excavating the literary record for evidence about the origins and development of oral tales,” they write. Translation: Researchers will still keep looking for the origins of fairy tales in books, too. In the meantime, it might be time to pick up that once-familiar storybook and dream about who told the same tales thousands of years ago.