Let's start with an example. We remember seeing a number in a dream. This number was super legit and also clear. But after waking up we can't remember the exact number.
The reason is how our vision works and how we remember things. When we look at a number, we get the raw image data through our eyes. Our brain process it similar to deep convolutional neural nets and converts it to a high-level representation.
To remember the number we build associations and find patterns in it. For example 33449, it starts with double 3, then double 4 (next digit after 3) and ends with 9. Easy.
But when you're dreaming the vision part of your brain is not working. You're not seeing raw data, so the numbers you see are already in their higher-level representation. It's actually possible that there are no numbers at all.
You're likely dreaming in even higher-level representation than digits. What happens next in the vision process is you convert the number to its meaning. Say, this is your pin code, or this is your height, or it is the amount of money you have in the bank. Basically, you don't care about the exact number anymore, but you know this number is legit, has some patterns that would help to reconstruct it if needed and it represents exactly the things it needs to represent. So in your dream, you don't need to get the reconstruction part. All you need is the final meaning.
When you wake up, you don't have the unique number from the dream. So your consciousness uses your real memory and the meaning from the dream to reconstruct the best-fitting number.
I've made an interesting observation. Closer to the moment when you are naturally waking up, more parts of your brain are joining the dream. You start to see more details and connect them to your memory. This causes discrepancies in the story and you realize that it's a just dream. It's also possible that you can make more decisions closer to being awake.
Anyway, dreams are a fascinating topic. I love seeing dreams, but having a kid who doesn't like to go to sleep early and an alarm for work doesn't help at all. Happy dreaming.