Sherlock Holmes, in any incarnation, packs a lot of information into his head, and he has to be ready to draw out those details as he makes his deductions and solves the most mysterious of mysteries. The Holmes of Sherlock, the BBC/Masterpiece program that aired its season finale Sunday night on PBS, is no exception. This time, though, his creators have gifted him with a talent for a mnemonic device straight out of ancient Greece—the mind palace. Of course, this being Holmes (and television), his version was somewhat more advanced than that of the average rememberer.

According to myth, the Greek poet Simonides of Ceos invented the technique after attending a banquet gone wrong. Simonides stepped outside to meet with two young men. But when he arrived outside, the young men were not there and the hall was collapsing behind him. Though his fellow banqueters were too badly crushed by the collapse for their remains to be identified, Simonides was supposedly able to put a name with each body based on where they had been sitting in the hall. That ability to remember based on location became the method of loci, also known as memory theater, the art of memory, the memory palace and mind palace.

To use the technique, visualize a complex place in which you could physically store a set of memories. That place is often a building such as a house, but it can also be something like a road with multiple addresses. In the house version, every room is home to a specific item you want to remember. To take advantage of the mind’s ability to hold onto visual memories, it often helps to embellish the item being stored—the milk you need to buy at the grocery store might become a vat of milk with a talking cow swimming in it. When those memories need to be recalled, you can walk through the building in your mind, seeing and remembering each item.

Greeks and Romans, such as the orator Cicero, employed the mind palace technique to memorize speeches, marking the order of what to say within a complicated architectural space. To write something down in that era was expensive and time consuming, a luxury not to be wasted, even on rhetoric The method of loci continued to flourish through the Middle Ages, when monks and other scholastics used it to commit religious texts to memory.

It fell out of favor, however, with the invention of the printing press. With books more easily available, there was less need for such powers of memorization. But the method’s popularity saw a resurgence in the latter half of the 20th century, particularly in international memory competitions, where skilled participants see it as a primary tool for recalling large numbers of items in order. Competitor Simon Reinhard holds the speed record for memorizing a pack of playing cards in 21.19 seconds at the German Open in 2011. And at the Swedish Open last year, Reinhard set another record, managing to memorize the order of 370 cards.

Given the technique’s power and history, it’s a little surprising that Arthur Conan Doyle never mentioned such a thing in his stories. Instead, he attributed his creation’s prodigious memory to an exceptionally well-organized, well-stocked “brain attic.”

“I consider that a man’s brain originally is like a little empty attic, and you have to stock it with such furniture as you choose,” Holmes tells John Watson in A Study in Scarlet, the first of Conan Doyle’s tales about the detective. Holmes is careful to fill his brain attic with only memories that may be useful, such as cases from the past. To make room for what was truly needed, Holmes tossed the rest out – even deeming unimportant the fact that the Earth circles the Sun. Watson, in contrast, has a brain attic more like the rest of us, jumbled with memories both valuable and inane, with none specifically selected for storage based on their potential future worth.

“The key insight from the brain attic is that you're only going to be able to remember something, and you can only really say you know it, if you can access it when you need it,” says Maria Konnikova, author of Mastermind: How to Think Like Sherlock Holmes. “Otherwise it might as well have disappeared,” she notes. The mind palace makes the idea more specific by organizing the information in a certain way. “The brain attic is much more broad,” Konnikova says.

A mind palace certainly sounds grander, befitting Holmes and his outsized ego, as Watson notes in season 2 of Sherlock. Sherlock Holmes’ mind palace, however, isn’t the typical type of storage place for the method of loci. Most people when they start out building a palace choose a place very familiar, such as the home they grew up in. But when viewers finally get a look inside Holmes’ palace during “His Last Vow,” the final episode of the latest season, they see something quite a bit different.

(Beware of spoilers from this point on.)

Holmes, after being shot point blank, delves into his palace to discover the best path to survival. Viewers see him stumbling down a winding staircase, then in a morgue-like room where he finds his friend Molly Hooper, the pathology lab assistant, looking over his own dead body. “You’re most certainly going to die, so you need to focus,” Hooper says. “It’s all well and clever having a mind palace, but you only have three seconds of consciousness left to use it.” Holmes discovers the answers to staying alive are indeed in his brain. But he goes beyond the classical mind palace technique, finding them not only by wandering through the building and locating items but also through conversations with the people he has stored there, like Hooper and his brother Mycroft.

In addition to the staircase and morgue, Holmes’ mind palace includes a long hallway with many doorways to rooms packed with memories. By searching those rooms, Holmes is able to find the memory of his childhood dog, Redbeard, which he uses to calm himself down. There’s also a padded room holding the now-deceased consulting criminal Jim Moriarty. All of these rooms don’t quite fit together, however, making it unlikely that Holmes’ memory palace is a real place.

But the method of loci doesn’t require a real location, at least according to research from the lab of Jeremy Caplan at the University of Alberta in Canada. A couple of years ago, Caplan and colleagues tested out a variation on the mind palace. They had a group of people develop a palace using the conventional method, with a real building they knew. A second group explored a virtual building on a computer screen for five minutes and were instructed to place their memories inside that structure. When tested on their memories, the two groups of participants performed equally well at memorizing a list of unrelated words, and both were better than a third group that was not using the method of loci.

“It was always thought that you had to use places that you could easily visualize, that you spent a lot of time in, so you had a really rich representation of that space. But what we showed was that you didn't actually need that,” says Eric Legge, lead author on the study.

It might also be possible to create a memory palace from a structure built entirely with the mind, says Christopher Madan, a co-author on the study. “It's probably a bit harder than if you had a real place to use because it adds another thing to remember,” he says. But a person with a lot of complex information to remember, and maybe a particularly gifted mind, say that of a British sleuth, might be able to construct a palace tailor-made for that type of information.

From the very first episode of Sherlock, it’s apparent that this Holmes’ mind doesn’t work like everyone else’s. Within moments of meeting Watson, the detective deduces his new acquaintance’s war history, living situation and the state of his family relations. And, in the midst of his best man speech at Watson’s wedding, Holmes has conversations with Mycroft in his head that prompt him to solve two attempted murders on the spot.

But viewers discover in the big reveal of “His Last Vow” that Holmes isn’t the only character to have a talent for building an extensive mind palace. Holmes’ foe, media magnate and blackmailer Charles Augustus Magnussen, has a mind palace of his own.

Early in the episode, we learn that Magnussen supposedly stores all of the evidence he uses for his blackmail schemes in a vault below his grand mansion Appledore. But, Magnussen later reveals to Holmes, “the Appledore vaults are my mind palace…I just sit here, I close my eyes, and down I go to my vaults. I can go anywhere inside my vaults, my memories.”

As with Holmes, Magnussen takes an unconventional route in the construction of his mind palace. He places his blackmail memories within a huge storage room, packed with shelves and filing cabinets. There are even movie screens where he can review events, such as Holmes’ rescue of Watson from a bonfire.

To construct such a mind palace would be more difficult, but “it’s still valid,” says Madan. A large, blank room wouldn’t work, but one that has identifiable locations within it might.

Less believable, though, is Magnussen’s “portable Appledore.” When the magnate is out and about, he seems to be accessing his mind palace as if the information were being presented as words on a screen sitting right in front of his eyes. Holmes sees this and assumes that Magnussen is receiving information through his glasses—perhaps an advanced form of Google Glass. Holmes is surprised when he later discovers that Magnussen’s Appledore storage vault is, in fact, a mind palace.

But viewers should forgive the detective for not deducing Magnussen’s method earlier. After all, when University of California, San Diego memory expert Larry Squire heard about how Magnussen seemed to be accessing his memories by reading them off a screen, Squire said, “that doesn’t sound right.”

This would, of course, hardly be the first time that a TV show has taken a wrong turn with biology. And even Holmes can’t be expected to predict what wild ideas today’s television producers might come up with.