If there’s a magic pill for happiness and longevity, we may have found it.

Countless studies have found that generosity, both volunteering and charitable donations, benefits young and old physically and psychologically.

The benefits of giving are significant, according to those studies: lower blood pressure, lower risk of dementia, less anxiety and depression, reduced cardiovascular risk and overall greater happiness.

“Volunteering moves people into the present and distracts the mind from the stresses and problems of the self,” said Stephen G. Post, founding director of the Center for Medical Humanities, Compassionate Care, and Bioethics at Stony Brook University School of Medicine in New York. “Many studies show that one of the best ways to deal with the hardships in life is not to just center on yourself but to take the opportunity to engage in simple acts of kindness.”

Studies show that when people think about helping others, they activate a part of the brain called the mesolimbic pathway, which is responsible for feelings of gratification. Helping others doles out happiness chemicals, including dopamine, endorphins that block pain signals and oxytocin, known as the tranquillity hormone. Even just the thought of giving money to a specific charity has this effect on the brain, research shows.

Intuition tells us that giving more to oneself is the best way to be happy. But that’s not the case, said Dan Ariely, professor of behavioral economics and psychology at Duke University.

“If you are a recipient of a good deed, you may have momentary happiness, but your long-term happiness is higher if you are the giver,” Ariely said. For example, if you give people a gift card for a Starbucks cappuccino and call them that evening and ask how happy they are, people say they are not happier than if you hadn’t given it to them. If you give another group a gift card and ask them to give it to a random person, when you call them at night, those people are happier.

“People are happier when they give, even if they’re just following instructions,” Ariely said. “They take credit for the giving and therefore are happier at the end of the day.”

The way we give is important, too, Ariely said. Taxes are a form of giving that typically does not make Americans happy. “In order to gain a personal benefit from volunteering, you have to focus on how your giving helps other people,” said Sara Konrath, director of the Interdisciplinary Program for Empathy and Altruism Research and assistant professor at the Lilly Family School of Philanthropy at Indiana University.

“We have the ability to shift our focus, and many of us do have an other-oriented reason for giving. If we can just focus on that aspect rather than what we can get out of it, chances are it will be better for our own health, too.”