The mammalian basal forebrain (BF) has important roles in controlling sleep and wakefulness, but the underlying neural circuit remains poorly understood. We examined the BF circuit by recording and optogenetically perturbing the activity of four genetically defined cell types across sleep-wake cycles and by comprehensively mapping their synaptic connections. Recordings from channelrhodopsin-2 (ChR2)-tagged neurons revealed that three BF cell types, cholinergic, glutamatergic and parvalbumin-positive (PV+) GABAergic neurons, were more active during wakefulness and rapid eye movement (REM) sleep (wake/REM active) than during non-REM (NREM) sleep, and activation of each cell type rapidly induced wakefulness. By contrast, activation of somatostatin-positive (SOM+) GABAergic neurons promoted NREM sleep, although only some of them were NREM active. Synaptically, the wake-promoting neurons were organized hierarchically by glutamatergic→cholinergic→PV+ neuron excitatory connections, and they all received inhibition from SOM+ neurons. Together, these findings reveal the basic organization of the BF circuit for sleep-wake control.