Key points: This study explores the state dependence of the hypercapnic ventilatory reflex (HCVR). We simulated an instantaneous increase or decrease of central chemoreceptor activity by activating or inhibiting the retrotrapezoid nucleus (RTN) by optogenetics in conscious rats. During quiet wake or non-REM sleep, hypercapnia increased both breathing frequency (fR) and tidal volume (VT) whereas, in REM sleep, hypercapnia increased VT exclusively. Optogenetic inhibition of RTN reduced VT in all sleep-wake states, but reduced fR only during quiet wake and non-REM sleep. RTN stimulation always increased VT but raised fR only in quiet wake and non-REM sleep. Phasic RTN stimulation produced active expiration and reduced early expiratory airflow (i.e. increased upper airway resistance) only during wake. We conclude that the HCVR is highly state-dependent. The HCVR is reduced during REM sleep because fR is no longer under chemoreceptor control and thus could explain why central sleep apnoea is less frequent in REM sleep. Breathing has different characteristics during quiet wake, non-REM or REM sleep, including variable dependence on PCO2. We investigated whether the retrotrapezoid nucleus (RTN), a proton-sensitive structure that mediates a large portion of the hypercapnic ventilatory reflex, regulates breathing differently during sleep vs. wake. Electroencephalogram, neck electromyogram, blood pressure, respiratory frequency (fR) and tidal volume (VT) were recorded in 28 conscious adult male Sprague-Dawley rats. Optogenetic stimulation of RTN with channelrhodopsin-2, or inhibition with archaerhodopsin, simulated an instantaneous increase or decrease of central chemoreceptor activity. Both opsins were delivered with PRSX8-promoter-containing lentiviral vectors. RTN and catecholaminergic neurons were transduced. During quiet wake or non-REM sleep, hypercapnia (3 or 6% FI,CO2 ) increased both fR and VT whereas, in REM sleep, hypercapnia increased VT exclusively. RTN inhibition always reduced VT but reduced fR only during quiet wake and non-REM sleep. RTN stimulation always increased VT but raised fR only in quiet wake and non-REM sleep. Blood pressure was unaffected by either stimulation or inhibition. Except in REM sleep, phasic RTN stimulation entrained and shortened the breathing cycle by selectively shortening the post-inspiratory phase. Phasic stimulation also produced active expiration and reduced early expiratory airflow but only during wake. VT is always regulated by RTN and CO2 but fR is regulated by CO2 and RTN only when the brainstem pattern generator is in autorhythmic mode (anaesthesia, non-REM sleep, quiet wake). The reduced contribution of RTN to breathing during REM sleep could explain why certain central apnoeas are less frequent during this sleep stage.