Rapid eye movement (REM) sleep consists of a dreaming state in which there is activation of the cortical and hippocampal electroencephalogram (EEG), rapid eye movements, and loss of muscle tone. Although REM sleep was discovered more than 50 years ago, the neuronal circuits responsible for switching between REM and non-REM (NREM) sleep remain poorly understood. Here we propose a brainstem flip–flop switch, consisting of mutually inhibitory REM-off and REM-on areas in the mesopontine tegmentum. Each side contains GABA (γ-aminobutyric acid)-ergic neurons that heavily innervate the other. The REM-on area also contains two populations of glutamatergic neurons. One set projects to the basal forebrain and regulates EEG components of REM sleep, whereas the other projects to the medulla and spinal cord and regulates atonia during REM sleep. The mutually inhibitory interactions of the REM-on and REM-off areas may form a flip–flop switch that sharpens state transitions and makes them vulnerable to sudden, unwanted transitions—for example, in narcolepsy. Rapid eye movement (REM) sleep is a dreaming state in which the brain is highly active. The mechanism responsible for switching between REM and non-REM sleep (also called slow-wave sleep, when cortical activity is slow) is poorly understood. Now, based on detailed anatomy and lesion experiments, Lu et al. have identified brainstem regions that control the transition from REM to non-REM sleep. The REM-off and REM-on areas are mutually inhibitory. This appears to produce a flip-flop switch relationship that could explain many of the properties of the abrupt switching into and out of REM states seen in sleep disorders such as narcolepsy.