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 things are clear after exercising and eventually happy.
At the same time, endorphins, another chemical to fight stress, is released in your brain. This is your endorphins main purpose; writes researcher McGovern:
These endorphins tend to minimize the discomfort of exercise, block the feeling of pain and are even associated with a feeling of euphoria.
The author of this article is Leo Widrich. The article talks about the effects of exercise on brain patterns.