Sleep is a unique state in which many of our body’s functions seem to be briefly suspended. Much like a bear that hibernates through the winter, we seem to temporarily enter a different metabolic state when we sleep. As part of this, many of the actions that we might expect to occur during the day are almost completely absent during our sleep. Why is this so?
In order to maintain a prolonged state of sleep overnight, we can’t be disrupted by the needs that fill our day. Imagine needing to wake to eat in the middle of the night, like a baby. Thankfully, our bodies are able to put these activities to rest during sleep. Therefore, we can normally make it through the night without feeling a need to eat, drink, urinate, or defecate. In various states of disease, or as a natural part of aging, however, this suppression may begin to fail. As an older person might attest, waking to urinate (as occurs in nocturia) can be greatly disrupting to a night’s rest.
Although we do not fully understand the metabolism of sleep, it is clear that there are hormonal changes that occur that allow us to use our stored energy (including from the liver) and suppress our desire to eat. Fasting 8 hours during the day is a somewhat uncomfortable feat, but it is accomplished easily on a nightly basis with the assistance of these hormones.
In addition, part of the wiring of our bodies called the autonomic nervous system remains active even during sleep. This helps to keep us breathing, sustain our heart rate, and continue digestion. These so-called "automatic" functions occur beyond our conscious control. You don’t have to think about the action for it to occur. As part of this, rings of muscle surrounding our orifices (called sphincters) are carefully controlled. As a result of this automatic control, we do not need to be conscious to avoid urinating or defecating in our sleep. Imagine having to constantly think, "Don’t pee," in order to control your bladder. As you fell asleep, the control would quickly be lost and you’d awaken to a wet bed.
In much the same way, there is autonomic control in the anal sphincter. This prevents the release of feces when you fall asleep. It also would control the release of gas. Therefore, you are likely only to pass gas when you reassert conscious control of the sphincter in the transition to wakefulness. You could then allow it to open at your will. You are unlikely to pass gas during sleep.
The rectum is exquisitely sensitive: You can sense whether the lower part of your sigmoid colon (called the rectal vault) contains air, stool, or liquid. This awareness fades away when you are asleep, but once you return to consciousness, you again recognize these sensations and respond to your body’s needs. This includes the need to pass gas, which seems to often occur upon awakening in the morning.
Why do we often pass gas in the morning? The answer is somewhat obvious: we need to. In fact, throughout the night, the healthy bacteria that work in our gut to help us digest food continue to do their work and create gas. As this gas accumulates, we may not release it while our autonomic nervous system maintains closure of the anal sphincter. However, when we awaken and realize that we need to pass gas, this inevitably follows.