Research shows that exercise is one of the best remedies for anxiety. It’s actually been found to be nearly as effective as Prozac at calming sensory nervous systems, producing feel-good hormones, lowering resting heart rate, increasing confidence, and decreasing sensitivity to anxiety symptoms. But cruelly, working out can also be a major trigger. Shallow breathing, a racing pulse, chest pressure, sweating, even slight nausea—these are all natural consequences of exertion; and they’re also symptoms of panic attacks. For me and the 3.3 million Americans with panic disorder, the sensations of exercise can morph seamlessly into full-fledged terror.

I’ve loved gyms since I was a high-schooler, burning off SAT stress and social drama on the elliptical machines. Throughout my adult life, I’ve cardio-kickboxed my way out of break-ups, and strength-trained into a self-assured, self-advocating woman. But during periods when I’m experiencing heightened anxiety, a workout can go from liberating to horrifying within seconds.

The amygdala, an ancient structure in the middle brain, sends out hormones to speed up heart rate, release adrenaline, and ready large muscles for action. The amygdala and the adrenal system are designed to override cognition and respond faster than the logical frontal cortex—so the second I have an anxious thought or feeling, I am flooded with chemicals bracing my body to fight or flee.

My pupils dilate so I can better spot danger, which makes the gym’s fluorescent lights garish and the people around me appear unreal. Blood is diverted away from my extremities to my core (so if I get cut I won’t bleed to death) and to my large muscles (biceps, quads), preparing them for action.

This redistribution of blood in my body causes me to feel faint, as well as an eerie sense of unreality and sensory overwhelm. My fingers and toes buzz from lack of circulation, and my lips and face blanch. Seeing my face so white and drained in the floor-to-ceiling wall mirrors scares me. I feel an impending doom, a black cloud descending. Dizzy and shaking, my mouth parched, my stomach cramping, legs quivering, I grab my water bottle and keys and flee the gym.

My overactive nervous system would have given me a great advantage for survival in Paleolithic times. But now it leaves me breathless and terrified at a luxury gym, with nothing to battle but a series of my own reflections in a row of spotless mirrors.

When panic plagues me, I avoid the gym and working out for months or a year at a time. People with panic disorder often develop agoraphobia, fear and avoidance of activities and places that could trigger panic. In times of acute anxiety I’m not able to go to work, to the store, or drive. On the worst days, I can’t even get out of bed—just venturing to the kitchen could trigger a devastating attack. I’ve had to crawl, quivering, back to my room more than once.

How exercise affects an anxiety-prone brain

One of the most touted benefits of exercise is the release of endorphins—pain-reducing chemicals that can create feelings of euphoria and relaxation. What’s more, exercise raises levels of a protein called brain-derived neurotrophic factor, which repairs brain cells that stress and depression damage. Opiate-like endocannabinoids also increase.

But during a workout, the stress hormone cortisol can rise, because exertion activates the sympathetic nervous system. People who have panic disorder are hyper-attuned to any increase in stress hormones and sympathetic nervous system arousal. They actually interpret those shifts in the body as dangerous—leading to more cortisol, adrenaline, and nervous system arousal. This cycle of escalating arousal and stress hormones can lead very quickly to a panic attack.

Ironically, in the long-term, exercise is associated with lower cortisol levels and nervous system arousal overall. So if someone with panic can tolerate the temporary increase in anxiety symptoms during and just after exercise, over time she’ll experience a net reduction in stress hormones and nervous system arousal—and greater calm.

The National Institute of Mental Health (NIMH) has found that regular aerobic exercise decreases the reactivity of both the sympathetic nervous system and the hypothalamic-pituitary-adrenal axis (another stress response system in the body). The NIMH also presents evidence that regular aerobic exercise has an effect on the brain similar to that of anti-anxiety meds like SSRIs. Exercise can also calm the amygdala, as well as stabilize sleep and appetite, and increase levels of GABA, a calming neurotransmitter, which is often naturally low in the brains of people with anxiety.

Because the normal side effects of exercise mimic the physical experience of panic, working out can also help desensitize sufferers to the physical symptoms of anxiety and panic. In other words, if you can tolerate the sweating, increased heart rate, muscle tension, and rapid breathing during exercise, you can also learn to bear those sensations when they arise due to anxiety. This is similar to exposure therapy, which incrementally exposes a person to what they fear in ways that do not seriously threaten them. Repeated exposures will eventually lead to better tolerance and less fear.

What I learned about panic at the gym

Easier said than done. Most people can hop on a treadmill and if their heart pounds, they recognize it as a sign they’re working hard. For the anxious and panic-prone, a racing heart and heavy breathing trigger worries, then images, then certainty of heart attacks, fainting, or dropping dead—and these scary thoughts trip off the adrenal system leading swiftly into a panic attack.

In exposure therapy, you confront what makes you anxious in small, simple steps, with a safety plan in place. I got back into exercise by raising my heart rate for short bouts. One day I walked vigorously around the block. The next I ran in place for five minutes in place in my backyard. When I ventured back to the gym, I did so for 10, then 15 minutes at a time, keeping my exertion level in check. When the anxiety became intense, I distracted myself with a comforting playlist, ice water, or a snack. If I felt on the verge of panic, I stepped outside, paced and breathed, and came back in, even if only for five more minutes.

I started going to Barre, which is strengthening and strenuous but not aerobic, so my heart rate stayed reassuringly low, and I could control how much strain I felt. My teacher reminded us that the exercises were supposed to feel uncomfortable, that’s how we’d get stronger. “Get comfortable with discomfort!” she cheered from the microphone clipped to her pink sports bra, while our legs quivered in squats and lunges.

This was great advice for us in class, and also for anyone with panic. I needed to learn to withstand the messages of terror and dread my body produced and that panic attacks, horrific as they are, were my body’s natural, if misguided, attempts at self-preservation. I needed to learn that the quaking of my body was a normal and expected outcome of exercise, not a sign of impending heart attack or mental collapse.

These feelings wouldn’t kill me. They wouldn’t cause insanity or permanent damage. They didn’t mean I actually needed to flee where I was. They would pass, like muscle fatigue when lifting, and rapid, gasping breathing when running or panicking.