People who take the popular sleep drug Ambien are more likely to recall bad or upsetting memories, says new research.

This could affect anyone living with anxiety disorders or Post-Traumatic Stress Disorder, especially soldiers: the Navy administers Ambien to help pilots and other soldiers counter the effects of stimulants used during long, grueling missions, the researchers say in the study.

Ambien, generically available as zolpidem, is a prescription sleep aid made by French pharmaceutical company Sanofi-Aventis. Health care research firm IMS reported about 40 million prescriptions were written in 2011 for some form of zolpidem.

While we sleep, our brains turn short-term memories collected during the day into long-term memories. Previously, study researcher Sara Mednick, of the University California Riverside, had found that sleep drugs containing zolpidem actually improved the brain's ability to turn short-term declarative memories — information about people, places, events, and so on — into long-term ones.

In her latest research, published in the Journal of Cognitive Neuroscience, Mednick's team found this stage of sleep is also important to how we remember things loaded with emotion, like trauma or tragedy.

But, there is a twist — when given Ambien, sleepers mostly recalled negative or upsetting emotions instead of pleasant or soothing ones.

A group of 28 participants looked at a series of images — for example, a roller coaster, a kitten, people standing around a grave, or an attacking snake — then took a sleep drug or a placebo, and went to sleep. After a few hours of sleep the participants were asked to recall the images they had been shown before their naps.

Ambien improved the ability to recall emotions and information better than both the placebo and another sleep drug called Xyrem (sodium oxydate), but most of what the subjects remembered was negative or upsetting.

"I was surprised by the specificity of the results, that the emotional memory improvement was specifically for the negative and high-arousal memories, and the ramifications of these results for people with anxiety disorders and PTSD," Mednick said in a press release. "These are people who already have heightened memory for negative and high-arousal memories. Sleep drugs might be improving their memories for things they don’t want to remember."

The human brain is built to remember negative memories better, said Mednick. Ambien seems to increase this natural inclination.

Most memories engage a brain region called the hippocampus, which is one of the areas responsible for recalling factual information. Emotional memories additionally engage the emotional center of the brain called the amygdala, which is especially sensitive to bad feelings, like fear and anger.

Negative memories might have a better chance of sticking because they engage a larger portion of the brain, the researchers suggested. This better memory might have presented an evolutionary advantage.

"You could imagine that things that are dangerous would be far more important to remember than something that is just a nice thing to experience," Mednick told Business Insider. "The more something evokes a fear response the more you would want to remember it so you could avoid encountering it again."