“In both writing and sleeping,” Stephen King wrote in his meditation on “creative sleep” and the art of wakeful dreaming, “we learn to be physically still at the same time we are encouraging our minds to unlock from the humdrum rational thinking of our daytime lives.” But while he was exploring the creative process from a metaphorical angle, he was inadvertently describing one of the greatest neurological nightmares that could befall us. Due to the sheer enormity of what happens in the brain while we sleep, there is also a sizable possibility that things would go wrong; when they do, things can get scary. And few sleep-related brain glitches can be scarier than what is known as “sleep paralysis” — the evil twin of lucid dreaming.

Four years after The Disappearing Spoon, his wonderful chronicle of crazy tales from the periodic table, science writer Sam Kean returns with The Tale of the Dueling Neurosurgeons: The History of the Human Brain as Revealed by True Stories of Trauma, Madness, and Recovery (public library) — a mind-bending tour of the mind, which Kean opens with a fascinating example, at once very personal and powerfully illustrative of the brain’s humbling complexity:

I can’t fall asleep on my back — or rather, I don’t dare to. In that position I often slip into a fugue state where my mind wakes up from a dream, but my body remains immobile. In this limbo I can still sense things around me: sunlight trickling through the curtains, passersby on the street below, the blanket tented on my upturned feet. But when I tell my body to yawn and stretch and get on with the day, nothing happens. I’ll recite the command again — Move, you — and the message echoes back, unheeded. I fight, I struggle, I strain to twiddle a toe or flex a nostril, and it does no good. It’s what being reincarnated as a statue would feel like. It’s the opposite of sleepwalking — it’s sleep paralysis. The worst part is the panic. Being awake, my mind expects my lungs to take full, hearty breaths — to feel my throat expanding and my sternum rising a good six inches. But my body — still asleep, physiologically — takes mere sips of air. I feel I’m suffocating, bit by bit, and panic begins to smolder in my chest.

But Kean, who is usually able to awaken his body within a few minutes, considers himself lucky — for others suffering from sleep paralysis, it can take hours of tortuous toiling. Some even slip into this half-asleep state in the middle of their day, while others have out-of-body experiences in the midst of trying to awaken their physical being. This is where Kean’s most fascinating point comes in — sleep paralysis may explain not only why a good deal of supernatural mythology came to be, but it also helps illustrate how the healthy brain works.

What causes sleep paralysis, Kean explains, is errant communication between the three main parts of the brain — the reptilian brain at the base, where functions like breathing and heart rate are controlled, the mammalian brain in the middle, which processes sensory input and includes the limbic system responsible for the formation of memories, and the outermost primate brain, which controls complex functions like movement, decision-making, and goal-setting. But while this trifecta of human consciousness generally hums along like the well-oiled machine that it is, every once in a while, communication between the different parts misfires — and then strange things happen. Sleep paralysis is just one such example. Kean writes:

Deep inside the reptile brain sits the pons, a hump in the brainstem an inch long. When we fall asleep, the pons initiates dreaming by sending signals through the mammal brain to the primate brain, where dreams stir to life. During dreams, the pons also dispatches a message to the spinal cord beneath it, which produces chemicals to make your muscles flaccid. This temporary paralysis prevents you from acting out nightmares by fleeing the bedroom or taking swings at werewolves. While mostly protective, this immobility sometimes backfires. Sleeping on your back can collapse the airways in your throat and deprive the lungs of oxygen. This isn’t a huge deal during nonparalyzed, nondream sleep: the parts of the brain that monitor oxygen levels will rouse your body a little, halfway to waking, and you’ll snort, shift your head, or roll over. To get oxygen during dream sleep, though, the brain has to order the pons to stop paralyzing your muscles. And for whatever reason — a chemical imbalance, a frayed neural wire — the pons doesn’t always obey. So while the brain succeeds in rousing the mind a little, it can’t turn off the spigot for the paralysis chemicals, and the muscles remain limp.

This produces a Rube Goldberg machine of neurological disaster: If this neither-here-nor-there state of wakeful immobility persists, the mind eventually becomes fully alert, realizes something has gone awry, and activates the amygdala — the brain’s alarm system, which amplifies fear. Suddenly, the brain is issuing a fight-or-flight command while the body is unable to perform either. Panic sets in. But this is where things get interesting — this anguishing state turns out to be a hotbed for the sort of hallucinatory experiences that people report when insisting they’ve had a brush with the supernatural. Kean explains:

At least with me, the actual dream I’m having stops as soon as my mind wakes up. Not so in some people: they never quite escape the dream state. They’re semialert to their surroundings, they’re paralyzed, and their brains keep conjuring up dream nonsense. Because the human mind is quite good at making spurious connections, they then link the characters in these hallucinations to their paralysis, as if one caused the other. It’s no wonder some people believe in demons and aliens: they actually see and feel them.

Beyond its science-over-myth quality, however, sleep paralysis demonstrates another incredibly important fact: in the brain, as in life, everything is connected to everything else. An error as tiny as the delicate chemical balance deep in the reptilian brain could produce something as large and abstract as belief in the supernatural. In fact, Kean points out, sleep paralysis is but one of countless neurological glitches that illuminate the complexity and interconnectedness of the brain — for instance, damage to a tiny cluster of neurons can render a person unable to recognize fruits and vegetables but not other food or unable to read but still capable of writing.

What such neurological malfunctions reveal about the wondrous workings of the brain is what Kean goes on to explore in the rest of The Tale of the Dueling Neurosurgeons, a fascinating read in its totality. Complement it with Oliver Sacks’s Hallucinations, then revisit the science of why we have nightmares.