system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How do our bodies learn not to pee when we are sleeping?
gpt
Peeing yourself while you are asleep is called 'nocturia' medically. There are several mechanisms your body uses to avoid this.

* Your kidneys slow down while you are asleep, so you don't pass as much water out to the bladder (the urine gets more concentrated and yellow as a result) and then don't need to pee as much while sleeping

* Sleeping suppresses how much you feel the fullness of your bladder, or more specifically the stretching of the detrusor muscle that wraps around the bladder

* The urinary sphincter is controlled by your autonomic nervous system, so just like your heart and lungs still keep going while you're asleep, so to does your ability to keep your urine in.

So there's certainly a lot of subconscious things going on, it's not so much learning. Your dog and your cat also manage to not pee themselves while they're sleeping, most of the time.

That said, it's not foolproof and nocturia happens in lots of people, for a variety of reasons. If you're concerned, see your doctor.