Sleep isn’t one solid state - it cycles through several stages every night. The most fascinating stage is REM, which stands for Rapid Eye Movement. During REM, your eyes dart around under closed eyelids, your brain is almost as active as when you’re awake, and you’re having vivid dreams.
To stop you from physically acting out those dreams (kicking, punching, running), the brain temporarily paralyzes most of your body during REM. The signals from your motor cortex still fire - your brain is “telling” your arms to move - but they don’t reach your muscles. This is called REM atonia. It’s why dreams sometimes feel like running but you can’t.
When the system fails, weird things happen. Sleep paralysis is when you wake up before your body comes back online - you’re conscious but can’t move. REM behavior disorder is the opposite - the paralysis doesn’t kick in, and people physically act out their dreams.