Scientists have found neurons that prevent mice from forming fearful memories in an area of the brain called the hippocampus.
These inhibitory neurons ensure that a neutral memory of a context or location is not contaminated by an unpleasant event occurring at the same time.
The team says their work could one day help them better understand the neural basis of conditions such as post traumatic stress disorder.
The study is published in Science.
Attila Losonczy, from Columbia University in New York and colleagues, were interested in how the hippocampus stores memories of a particular context and then separates this memory from a fearful event.
When looking at individual neurons in the brains of mice, they found inhibitory cells - called interneurons - were crucial for fear memory formation to travel to the correct part of the brain.
"These cells are activated by the unpleasant salient event and they act somewhat like a filter. They may function to block out unwanted information related to this strong, salient event," Dr Losonczy told the BBC's Science in Action programme.
"This way, the hippocampus can process and store contextual information reliably and independently without the potentially detrimental interference from this [unpleasant] salient event," he added.
When mice were conditioned to express fear in a particular context, they later associated the same environment with the unpleasant event.
But when scientists deactivated these inhibitor neurons, the mice no longer showed any fear. That is, the team was able to stop the mice from forming fearful memories.
This highlighted the importance of the role of these interneurons on first encoding the fearful memory before it was passed onto another part of the brain.
"The next time this aversive stimulus is not present, we should still be able to remember the context correctly," Dr Losonczy explained.
"This contextual representation is then played out from the hippocampus to other brain areas like the amgydala where the actual association between the context and the fearful event takes place."
Understanding how context and fear are learned and the specific neurons involved, could help scientists better help people with conditions like anxiety and post-traumatic stress disorders.
"If we understand how the circuits in our brain influence memory under normal conditions, we can then try to understand what actually went wrong during psychiatric disorders," added Dr Losonczy.
Xu Liu from the Massachusetts Institute of Technology, US, who was not involved with the research, said that the study was a cleverly designed way to "peek into the mouse's brain and zoom into the cells of interest while the animal was learning".
"This study solved the puzzle of how the hippocampus can successfully encode the context, while ignoring the impact of the ongoing negative stimulus."
"[It] shows one mechanism for parallel-processing in the brain, where temporally overlapping inputs are disentangled and sorted into separate pipelines for further processing," Dr Liu told BBC News.