It's not clear whether the brain actually is designed to have nightmares or whether this is actually the process going awry. Matthew Walker Design Whether T