Dreams are usually stored in the short term memory. If you want to remember your dreams, you have to try to recall them within the first five minutes of waking up or they are usually completely forgotten. You have about 10 dreams a night so it's difficult to remember all of them. You can only remember every dream if you woke up during or immediately after each one. While you sleep, your brain doesn't just turn off. It goes through several stages of sleep, including REM, or Rapid Eye Movement, sleep. In this stage of your sleep, your eyes move back and forth under your closed eyelids.
During REM sleep, you have dreams and sometimes those dreams can be scary or upsetting. About every 90 minutes, your brain switches between non-REM sleep and REM sleep. The amount of time spent in REM sleep increases with each sleep cycle through the night. The longest periods of REM sleep occur towards the morning. If you wake up during this REM stage, it is easier for you to remember what you were dreaming about.