Knowing that you are in a dream while you are asleep is called lucid dreaming. It's scientifically proven that it only occurs when you notice something that cannot possibly exist in the real world. A method for trying to induce lucid dreaming is to write down your dreams immediately after you wake up...most people have patterns in their dreams. For example I had a dream that godzilla was running around refridgerators in my playroom when I was younger. That was an easy one to spot, and a common pattern in my dreams consistently involves me being chased by strange creatures (I'm not making this up, I wish I could just have more sex dreams and less me getting chased by creatures dreams).