Well I'm no expert, but as far as I know there's different stages to sleep. REM (Rapid Eye Movement) is the one where you dream. In order to remember your dreams, you must wake up either in the middle of REM (when the dream is happening) or immediately after it. Otherwise you're waking up during a time when you're not dreaming, so the memories are not stored. What's interesting is that the brain doesn't really "store" memories of dreams (at least in the same way "regular" memories are stored), so the only reason you remember a dream when wake up during REM is that your brain abruptly transitions between the sleeping and awake states, so the dream is still "fresh."
It is recommended to keep a journal of every dream you remember and write on it as soon as you wake up, describing your dream "backwards" (with the last events of the dream first and going back until you can no longer remember), as you'll remember less and less of the dream as the day goes on. I'm not really sure how this helps, but people who do it claim they develop better dream retention over time.