Two Christmases ago, my cousin gave me a waterproof notepad and pencil. I chuckled when I unwrapped the package and later, stowed it in the back of a closet. How cliché, I thought. Not all writers get their best ideas in the shower.

Except I do. In fact, it happened again today as I was thinking about writing this article. I had my research and interview notes in front of me but just couldn’t figure out the best way to pull everything together. After procrastinating with a few episodes of “The Americans” (sorry editors!), I decided to take a break and shower. As soon as I stepped into the tub, it’s as if the water unleashed another part of my brain. Out of the blue, a flood of words and sentences poured forth and my thesis was suddenly clear. Why does this happen? Our brains have a method for this creative madness, when an insight seems to emerge suddenly and magically and we break through a mental barrier. According to John Kounios, a professor of psychology at Drexel University and co-author of “The Eureka Factor: Aha Moments, Creative Insight, and the Brain”, there are two paths the brain can take to solve a problem. There’s analytical path, where we deliberately and methodically work through a problem by trying out different solutions. Then, there’s insight, where a solution seems to pop into our heads out of nowhere, a so-called aha! moment. “It seems disconnected from your ongoing stream of thought,” says Kounios.

Kounios has been studying these moments of insight for many years. Recently, thanks to the advances in neuroimaging technology, he and his collaborator Mark Beeman from Northwestern University have been able to see what actually happens in the brain when we have a mental or creative breakthrough. For their experiments, they asked participants to solve a series of verbal puzzles and used EEG and fMRI imaging to examine the brain’s activity. They found that participants who solved the problems through insight experienced a burst of activity in the right temporal lobe of the brain. “It’s a particular area that’s connected to lots of other areas of the brain. It seems to make connections or associations between different ideas or sensations,” says Kounios. It’s also the area associated with our understanding of jokes and metaphors, which sometimes require a mental leap to “get it.” More interestingly, the brain “blinks” right before an aha! moment. There’s a rush of alpha waves in the back of the brain, shutting down activity in the visual cortex (the part of the brain that processes visual and perceptual information) in the same way that you might close your eyes or look away from a problem before reaching an epiphany. “Just before you have an insight you become momentarily less aware of your environment,” says Kounios. This “brain blink” cuts out distraction and allows us to focus inward so that our subconscious can make connections between ideas and bits of knowledge already stored in the brain. Then, eureka! The solution pops into our consciousness.

Read more: Why smells are like time machines

In contrast, the participants who solved the problems analytically saw more activity in the frontal lobe of the brain, responsible for focus, organization, and attention. They also saw that right before a problem is presented, an analytical person’s brain focuses attention outward, soaking up as much information as possible. So then, why do activities like walking, running, or showering seem to produce a high number of eureka moments? It’s because they may help put the brain in the right state of mind to have an aha! moment. Exercising or being in nature releases a rush of endorphins that can promote a positive, relaxed mood. This, in turn, can broaden your scope of thought to include remote ideas and long-shot possibilities, says Kounios. “You are open to entertaining ideas that, at first blush, may seem a little wacky. You feel like you can take chances.” When you’re anxious, you tend to think more analytically. “It narrows the focus of attention, like mental tunnel vision,” he adds. Stepping away from a difficult problem or a bad case of writer’s block with a walk also distracts the brain just enough to give it a chance to rest. When you stop thinking deliberately about a problem and daydream a little, your subconscious has a chance to play. Studies have found that after a period of mind wandering, the mind makes more creative connections between bits of information you already know. As for the shower? It’s kind of the ideal epiphany incubator. Not only does the warm water elevate your mood, you focus your attention inward. “You have some mild sensory deprivation. You can’t see very much. There’s the white noise of the water. The water is warm so you can’t feel the difference between your skin and the air,” says Kounios. “This sensory restriction is like an extended brain blink. You cut out the outside world and ideas bubble up into awareness.” So, next time you’re stuck on a problem, try taking a break and letting your mind wander. Or just take a shower. You never know. An epiphany just might be waiting for you.