Why we dream is a conundrum that has puzzled scientists for decades.
Some believe it allows us to live out our subconscious desires, while others claim dreams enable us to process what we experience while awake.
And now research suggests nightmares may help us cope with our fears.
Scientists from the US and Switzerland scanned the brains of 18 slumbering volunteers.
The participants were hooked up to more than 250 electrodes, which collected data on the “emotions” they were likely experiencing while asleep.
Results, published in the journal Human Brain Mapping, suggest activity increased in the insula and midcingulate cortex in response to “dreams containing fear”.
These areas of the brain regulate the “perception of negative emotions”,
In a second part of the experiment, 89 people kept a dream diary for a week, where they also noted the emotions they felt during the day.
They then underwent brain scans while viewing distressing images.
“We showed each participant emotionally-negative images, such as assaults or distressful situations, as well as neutral images, to see which areas of the brain were more active for fear”, study author Virginie Sterpenich, from the University of Geneva, said.
“And whether the activated area changed depending on the emotions experienced in the dreams over the previous week,” Metro reported.
The scientists found those who experienced a “higher incidence of fear in their dreams” had “reduced emotional arousal” in their insula and midcingulate cortex in response to “fear-eliciting stimuli”.
And the more bad dreams they had, the better they coped, the results suggest.
The team believe encountering threatening behaviour in a “safe” space while we sleep may be a “rehearsal” in case a similar scenario plays out in real life.
“Dreams may be considered as a real training for our future reactions and may potentially prepare us to face real life dangers,” study author Lampros Perogamvros, from the University of Geneva, said.
However, truly terrifying nightmares were found to have a negative effect, including insomnia.
“If a certain threshold of fear is exceeded in a dream, it loses its beneficial role as an emotional regulator,” Mr Perogamvros told the BBC.
The scientists hope dreams could one day be used as a form of “densitisation” therapy for anxiety sufferers.