One night, a man dreamed that a wild boar was loose in his house. Not that extraordinary-except that he got up and did something about it. While asleep and dreaming, he retrieved the box containing his pistol, opened the combination lock, loaded the gun, chased the “boar” outside, and fired on it twice. Just as he was going back inside, he woke up-he had stubbed his toe on the front steps.

While most people aren’t so rowdy at night, sleep isn’t as passive as you might think.

The body’s light switch doesn’t just turn off,” says Bradley Vaughn, assistant professor of neurology. Your brain, he explains, simply changes state.

To realize how well the brain must work to accomplish an ordinary task such as sleep, you only have to see what happens when something goes wrong. The boar-chasing man, for example, came to Carolina’s Sleep Center and was diagnosed with REM behavior disorder (RBD). Normally, during REM-one of the five stages of sleep, named for the rapid eye movements that accompany it-your brain sends out chemicals that paralyze your large muscles. But if you have RBD, the neurons responsible for those chemicals don’t fire, so you have full movement of your limbs while dreaming.

People with RBD can perform elaborate tasks while asleep because the brain still picks up some sensory information while in REM, Vaughn says. “Have you ever been dreaming about a song, and then wake up and realize that that song was actually playing on the radio? That’s because you incorporate sensory phenomena and associate it with your dream.”

Acting out dreams can be dangerous. The patient who had dreamed about the boar was a “very mild-mannered, average Joe, helped out at his church,” Vaughn says. “But at night he was under a different influence.” His wife had begun to sleep at a relative’s house because of his violent nighttime episodes.

Fortunately, RBD can be controlled in 90 percent of patients using clonazepam, a drug often prescribed for seizures or panic disorder. RBD also seems to be a sign of other malfunctions in the brain-some patients eventually develop Parkinson’s disease.

RBD was clinically recognized only in the late 1980s, so it’s not certain how common it is. Carolina’s sleep lab has diagnosed about 40 cases. Doing that requires a sleep study, in which a patient spends the night while his brain waves, breath flow, limb and eye movements, heart rate, and muscle tone are monitored.

A sleep study involves connecting the patient to 16 different electrodes. Those attached on either side of the head produce an EEG (electroencephalogram), which together with eye-movement and muscle-tone readings indicate the stage of sleep.

We cycle through the five stages of sleep several times a night-about every 90 minutes. Vaughn explains the differences between the stages. When you’re awake, the EEG shows a “fast buzz” of high-frequency waves known as alpha waves. Also your eyes move pretty quickly, and your muscle tone-measured with an electrode under the chin-is high. As you fall into stage-one sleep, the EEG begins to slow down, and your eyes show slower, rolling eye movements. Stage two is marked by sleep spindles, which are tiny waves with a fast frequency, and the k complex, which is a bigger wave that resembles a check mark. In sleep stages three and four, your brain waves slow down, but have higher crests.

Then at the onset of REM, your EEG starts to flatten out-the waves come at a high frequency but are low. You also have rapid eye movement, and muscle tone decreases. REM is similar in depth to stage one or two-it doesn’t take much to wake you.

The somnogram that results from all the electrode measurements appears to be just a bunch of wavy lines, but a sleep specialist can see in it a surprising amount about a patient’s health.

Brian Boehlecke, associate professor of medicine, sees many of the patients who come to the sleep lab. While evaluating one study, he explains, “This woman has a real problem. See this fast buzz in here? She’s got alpha waves in the background of her slow wave and REM sleep. She’s got alpha-intrusion or alpha-delta sleep.” Her sleep isn’t as deep and restful as it should be-it’s so-called “dirty sleep.” “Cleaning up” her sleep may require finding and treating any chronic pain that she may be having, or making sure all the medications she’s on are necessary.

This woman was also having an apnea-stoppage of breathing-several times a night. Boehlecke could see them as dips in the waves that measure air flowing out of the nose and mouth. Obstructive apnea occurs because of a collapse of the airway just above the windpipe, Boehlecke says. This blockage can be caused in part by swollen nasal passages from allergies, large tonsils, or a short, wide neck with a narrow airway. Sufferers may stop breathing as many as 120 times per hour, and each time usually wake up, if only for a few seconds.

Sleep apnea seems to increase the risk of heart attack and stroke. But the exact amount of risk it contributes is unknown, since many apnea sufferers are overweight or have other medical conditions. Someone with obstructive apnea can improve dramatically by sleeping with a special mask over his or her nose. The mask is attached to a pump that continuously blows air to maintain pressure to keep the airway open. Another option is surgery to widen the upper airway. Many people report dramatic improvements in their alertness after treatment-they hadn’t realized they were fatigued.

Quality of sleep is entwined with general health, Boehlecke says. At Carolina, sleep specialists see patients for a thorough history and physical before ordering a study in the lab. With treatment of chronic pain or nasal congestion, some patients improve even before undergoing a full sleep study. “We don’t want to do an expensive test only to find out that the person has chronic pain, and that’s why they’re not sleeping well,” Boehlecke says.

One night in the sleep lab costs $2,000. “You’ve got about a quarter of a million dollars’ worth of equipment hooked up to you,” Vaughn says. He is working on a less expensive preliminary sleep evaluation that would measure heart-rate variability. The mathematical model he’s developing could distinguish between REM sleep, for example, when your heart rate varies widely, and slow-wave sleep, when there’s less variability.

While knowledge of sleep stage helps scientists treat disorders, the purpose of sleep and its stages is unknown. Entering REM sleep, for example, is akin to becoming a different animal. Your muscles are paralyzed, your brain fires a rapid succession of images, and your body temperature becomes like a reptile’s-you can no longer regulate it on your own. Some scientists think that REM helps cement memories, while others say it’s a way to ease into wakefulness-to ensure that we don’t get trapped in a deeper stage of sleep. But no one is sure. “We do know that if you’re dream-sleep deprived, you’re more likely to have trouble with memory and learning new tasks, with higher cognitive functions,” Vaughn says. “But do we know if that’s the purpose of dreaming? No.”

Scientists are certain that we need an adequate amount of sleep. In lab experiments, sleep-deprived rats will experience organ failure and die after about three weeks. And humans with the rare disease fatal familial insomnia, in which their ability to sleep dramatically decreases, will also eventually die of organ and nervous-system failure. But the exact reason why-like the appearance of a wild boar in a dream-is a mystery.