During sleep, especially REM sleep, the brain replays and reorganizes experiences, strengthening important memories and weakening unnecessary ones.