With a sigh, Johnny Perez rises from his plastic chair, unfolds his lanky frame, and extends his wingspan until the tips of his middle fingers graze the walls. "It was from here to here," he says. "I know because I used to do this all the time." Until recently, these measurements — 10 feet by 6 feet — fit his entire life.

Two years ago, Perez was released on parole after serving 13 years in prison in New York; he spent three of those years in solitary confinement. Sitting across from Perez, you wonder how he feels in this space, a tiny, harshly lit conference room at the Urban Justice Center on Wall Street in Manhattan. Whether it brings back traumatic memories, or feels like home, or both.

While there is no universally agreed upon definition, modern solitary — also called supermax or the box — is commonly understood to involve confinement to a small cell for 22 to 24 hours a day. Prisoners are not allowed to participate in leisure activities, have hobbies, or speak to others. They are often shackled when they leave their cells — if they ever leave. Perez says he eventually stopped even wanting to.

Solitary confinement has been linked to a variety of profoundly negative psychological outcomes, including suicidal tendencies and spatial and cognitive distortions. Confinement-induced stress can shrink parts of the brain, including the hippocampus, which is responsible for memory, spatial orientation, and control of emotions. Prisoners often report bizarre and disturbing subjective experiences after they leave supermax. Some say the world regularly collapses in on itself. Others report they are unable to sustain ordinary conversations, or think clearly for any length of time. The psychiatrist Sandra Schank puts it this way: "It's a standard psychiatric concept, if you put people in isolation, they will go insane."

Yet Perez pauses when he is asked how it felt to be confined for so long. "That's an interesting question," he says. "Because in a sense, you are confined, and in other senses, you're free." Perez says he left solitary confinement a better man than he entered it. He is now fully rehabilitated and works for the Urban Justice Center, where he helps recently released inmates adjust to the world outside.

Perez calls himself an "anomaly" and says he can only guess at the factors that made him succeed where so many others have failed. However he did it, what's clear is that the process began with his own imagination.

At the end of this short paragraph, stop reading. Close your eyes. Imagine yourself hitting a tennis ball. Do it again.

Can you see yourself hitting the ball? Can you visualize its arc through the sky? Does it veer off course, and can you imagine yourself hitting it better next time?

If so, you are using a technique that has helped many people survive prison. Edith Bone, a professor of medicine and a translator who spoke six languages fluently, constructed an abacus out of stale bread and made an inventory of her sprawling vocabulary while imprisoned in Hungary after World War II. Hussain Al-Shahristani, Saddam Hussein's former chief scientific adviser, spent a decade in solitary confinement at the Abu Ghraib prison near Baghdad. He survived, according to the BBC, by "taking refuge in a world of abstractions, making up mathematical problems, which he then tried to solve." He is now Iraq's minister of higher education and scientific research. While imprisoned in a German concentration camp during World War II, the Russian Jewish mathematics professor Jakow Trachtenberg developed an innovative method of performing rapid mental calculations, known today as the Trachtenberg system.

Summoning up mental imagery is a "quasi-perceptual experience," according to the Concise Corsini Encyclopedia of Psychology and Behavioral Sciences. It stimulates the brain's frontal lobe, which is associated with higher cognitive processes and abstract thought — as well as perception and motor control. That can make it feel real.

For this reason, mental imagery is an ideal portable training tool. Just imagine yourself kicking the ball or delivering the punch line, and you'll have better control over how your foot swings or your voice projects. In one study, running an imaginary course activated muscle patterns in the legs of skiers similar to those produced by actual skiing. The phenomenon, known as the Carpenter effect, has also been seen in studies of tennis and volleyball teams. Athletes with closed eyes swaying through an imaginary course have become a common sight in the starting areas of ski races and bobsled tracks.

Mental imagery can supplement perceptual input — but it can be equally useful when perceptual input is painful, tedious, or lacking. A prisoner in supermax can use imagery to create the space and time that confinement strips away. While he was in "the box," Perez talked to himself out loud. He kept journals. For a while, he wrote out and responded to famous quotations.

He also used his mind to time-travel, imagining "alternate endings to past interactions with people: What if I said this? Or what if I would've invited her for coffee or something like that?" He wrote about painful relationships and episodes, reframing them and extracting a lesson. Memory is both constructive and reproductive, says Alex Schlegel, a cognitive neuroscientist at the University of California, Santa Barbara. In fact, imagination and memory run on parallel tracks in the brain. By engaging his imagination, Perez was able to "rewrite" his past in a more positive light, and reframe his future.

"I used to lie in bed with my eyes closed," says Perez, "thinking about my past, thinking about my future, planning for the future. Some of it was based on reality, and the other — borderline fantasy." He tapped into a tunnel-like experience, creating a personal space for himself inside the tiny physical space of his cell. Over time, he got more intentional about how he was using his time in his "mental workspace," as Schlegel refers to the overlapping networks that allow intentional imagination to take place. Perez believes what he ended up doing "bordered on meditation."

Michael Jewell, a Texas inmate, had a similar experience. After Jewell's 1970 death sentence was commuted to life imprisonment, he served 40 years, seven of which were spent in near-total isolation. He says he used to kill time for hours working out detailed visualizations of himself in a vivid alternate reality, where he could inhabit open spaces and converse with people.

"I might imagine myself at a park and come upon a person sitting on a bench," he says. "I would ask if she or he minded if I sat down. I'd say something like, 'Great weather today.' The other person would respond something like, 'It is indeed. I hope it continues until the [football game].' As we conversed, I would watch joggers, bicyclists, and skateboarders pass by. The conversation might go on for half an hour or so. When I opened my eyes and stood, I would feel refreshed and even invigorated."

As with Perez, the result was self-improvement in the most unlikely circumstances. "I was an exception to the rule," Jewell writes. "I went out better than I came in." In a sense, Jewell didn't have much of a choice. A survivor of intense childhood trauma and abuse, he says the constant presence of mental "goblins" threatened to consume him when he entered solitary. His willful and directed imagination was a reaction to those goblins, and helped him defeat them. Now on parole, Jewell is active on many prison reform boards and is a director of Texas Cure, an organization that works on prison reform.

That Perez and Jewell had an active imagined life in solitary is, in a sense, unsurprising. Isolation naturally encourages the generation of mental imagery, because imagination and perception occur along parallel neural pathways and are constantly competing for attention. The more there is to perceive, the less intense our mental imagery will be. Conversely, reduced sensory stimulation can allow for "vivid and stable mental imagery," says David Pearson, a cognitive psychologist at Anglia Ruskin University. This correlation has been documented before: Isolation has been linked to creativity.

But simply imagining something is not enough to improve well-being. In fact, uncontrolled or intrusive mental images can be both causative and symptomatic of mental illness. Social anxiety sufferers, for example, are plagued with involuntary images of themselves performing badly in social situations. A stutterer might picture himself stumbling over a word repeatedly. The problem is particularly severe in prison: Fifty-five percent of male and 73 percent of female inmates in U.S. state prisons suffer from some form of mental illness.

Uncontrolled and intentional imagination lead to very different outcomes. They even activate different parts of the brain. The default-mode network, which goes online when we let our minds wander, is associated with uncontrolled imagination. Controlled imagination activates the dorsal attention network, which is linked to self-control, and the impairment of which might be implicated in psychological disorders like substance dependence and attention deficit disorder. Which kind of imagination is activated may come down, simply, to character.

Angela Duckworth was teaching seventh-grade math in a New York City public school when she noticed that intelligence was not always the best predictor of which of her students would succeed. There was another key ingredient: the ability to demonstrate effort and passion over time, a quality she called "grit."

Duckworth went on to obtain a doctorate in psychology at the University of Pennsylvania, and developed her hypothesis further. She has since researched West Point Military Academy cadets, National Spelling Bee competitors, rookie teachers in low-income neighborhoods, and salespeople at top companies. Across all of these professions, she has found grit to be a key ingredient in achievement. Students who self-report high grit levels are more likely to succeed in school than non-gritty students — even more intelligent ones.

But grit isn't just about achievement. In fact, achievement can obscure grit. Duckworth writes, "Whereas individuals high in need for achievement pursue goals that are neither too easy nor too hard, individuals high in grit deliberately set for themselves extremely long-term objectives and do not swerve from them — even in the absence of positive feedback."

There's not much in the way of positive feedback in solitary confinement. Success is almost completely unrecognized by others and entirely dependent on the goals you set yourself. Schlegel posits that prisoners who thrive in solitary confinement probably have extra-high levels of grit: "There's this motivation aspect to creativity that's really separate from anything to do with imagination," he says. "This idea of motivation is very underappreciated."

For this article, Perez and Jewell took an online test through the University of Pennsylvania's Grit Lab that measured their grit on a scale from 1 to 5. The test measures qualities like an individual's consistency of interests ("I often set a new goal but later choose to pursue a different one") and perseverance in effort ("I have achieved a goal that took years of work"). Both Jewell and Perez scored a 4.25, meaning they are grittier than 90 percent of the U.S. population.

Jewell agrees that grit may have played a role in his anomalous supermax experience and says that his upbringing may have made him "grittier than his counterparts." For his part, Perez says that the experience of confinement has made him even grittier. "The way I see it is like this," he says. "I have been to the bottom of the barrel and have emerged more resilient, smarter, more determined to succeed, and more appreciative about the small things in life. I learned to eliminate the pain by finding pleasure in the pain, to turn s--- into sugar."

Grit and imagination got him through and helped make him who he is today. At the same time, he says, he didn't need all those years in prison to "get the message."

"Would I take it back?" Perez chuckles and leans back, shaking his head. "Yeah, probably."

Excerpted from an article that originally appeared in Nautil.us. Reprinted with permission.