How do we dream and what are nightmares?

How do we dream and what are nightmares?