Science has already revealed how "endorphins are released" whenever you exercise, but here's a more scientific explanation on how physical activity actually affects the human brain to help lighten up your mood:
If you start exercising, your brain recognizes this as a moment of stress. As your heart pressure increases, the brain thinks you are either fighting the enemy or fleeing from it. To protect yourself and your brain from stress, you release a protein called BDNF (Brain-Derived Neurotrophic Factor). This BDNF has a protective and also reparative element to your memory neurons and acts as a reset switch. That's why we often feel so at ease and like things are clear after exercising.
What's interesting is that other studies have shown that BDNF and endorphins have a very similar and addictive behavior like morphine, heroin, or nicotine. But unlike those illegal drugs, endorphins are actually good for us.


And the great news is that science is also trying to figure out effective ways to trigger these endorphins and to make them last longer. A recent study from Penn State found that to be more productive and happier on a given work day, it doesn't matter so much, if you work-out regularly, that you haven't worked out on that particular day:
"Those who had exercised during the preceding month but not on the day of testing generally did better on the memory test than those who had been sedentary, but did not perform nearly as well as those who had worked out that morning."
So it doesn't matter so much if you work-out regularly or that you haven't worked out on that particular day. A much smaller amount of daily exercise (20-30 minutes) is all anyone really needs in order to reach the level where happiness and productivity in every day life.

via Buffer