If you’ve ever taken a break from coffee (assuming you’re a regular drinker), then you can probably recall caffeine withdrawal symptoms like headaches, irritability, and lack of concentration. It’s no secret that caffeine can improve people’s moods, but scientists have long wondered how. Is there a chemical process involved? Or maybe it’s just the simple pleasure of sitting down with a cup of coffee in hand, sometimes with friends, too. In a new study, an international team of scientists are saying it’s the former.

Researchers from Portugal, the United States, and Brazil discovered that mice given caffeine were better able to handle stress than mice subjected to stressful situations sans caffeine. The reason: While caffeine usually blocks adenosine receptors from activating sleep processes, it also prevents the receptors from reacting to, and causing a stress response, including a bad mood, memory problems, and an enhanced susceptibility to depression, the researchers said.

“What caffeine is doing is not making the system work better; what caffeine is doing is avoiding the system going into the wrong way of working,” Rodrigo Cunha, an associate professor at the University of Coimbra in Portugal, told ABC News Australia. “So it’s a prevention of a deterioration rather than an improvement.”

Stress is a normal human response that can help a person push themselves harder in the face of challenges. However, it begins to affect a range of bodily processes over an extended period of time. For this reason, it’s been linked to insomnia, obesity, and mental health disorders. Thirty-three percent of Americans never discuss ways to manage it with a health care provider either, according to the American Psychological Association.

For the study, researchers gave some mice caffeine in their drinking water while others received plain water. The mice were exposed to sudden, stressful situations three weeks after starting this caffeine regimen, which included damp bedding, sharing living space with other mice, being deprived of food and water, cold baths, and having cages tilted at 45-degree angles. The researchers found only mice that went without caffeine experienced stress-induced changes to their brains and behavior. What’s more, the same changes occurred when the mice were given a drug meant to block adenosine receptor activity, as well as when all genes for adenosine receptors were deleted.

While Cunha says the link between caffeine and better management of stress is causal — because they “didn’t go to the coffee shop” or “spend more time with each other” — the fact remains that the experiments were only conducted on mice. Future studies will determine whether these effects are similar in humans, and whether drugs can be developed to target adenosine receptors in order to “alleviate the consequences of chronic stress on brain function,” the researchers wrote.

Source: Kaster M, Machado N, Silva H, et al. Caffeine acts through neuronal adenosine A2A receptors to prevent mood and memory dysfunction triggered by chronic stress. PNAS. 2015.