The writings of Lincoln, the Rev. Martin Luther King Jr., Gandhi and Nelson Mandela, Mr. Obama found, were “particularly helpful” when “what you wanted was a sense of solidarity,” adding “during very difficult moments, this job can be very isolating.” “So sometimes you have to sort of hop across history to find folks who have been similarly feeling isolated, and that’s been useful.” There is a handwritten copy of the Gettysburg Address in the Lincoln Bedroom, and sometimes, in the evening, Mr. Obama says, he would wander over from his home office to read it.

Photo

President Obama in the Oval Office in 2012.Credit
Damon Winter/The New York Times

Like Lincoln, Mr. Obama taught himself how to write, and for him, too, words became a way to define himself, and to communicate his ideas and ideals to the world. In fact, there is a clear, shining line connecting Lincoln and King, and President Obama. In speeches like the ones delivered in Charleston and Selma, he has followed in their footsteps, putting his mastery of language in the service of a sweeping historical vision, which, like theirs, situates our current struggles with race and injustice in a historical continuum that traces how far we’ve come and how far we have yet to go. It’s a vision of America as an unfinished project — a continuing, more-than-two-century journey to make the promises of the Declaration of Independence real for everyone — rooted both in Scripture and the possibility of redemption, and a more existential belief that we can continually remake ourselves. And it’s a vision shared by the civil rights movement, which overcame obstacle after obstacle, and persevered in the face of daunting odds.

Mr. Obama’s long view of history and the optimism (combined with a stirring reminder of the hard work required by democracy) that he articulated in his farewell speech last week are part of a hard-won faith, grounded in his reading, in his knowledge of history (and its unexpected zigs and zags), and his embrace of artists like Shakespeare who saw the human situation entire: its follies, cruelties and mad blunders, but also its resilience, decencies and acts of grace. The playwright’s tragedies, he says, have been “foundational for me in understanding how certain patterns repeat themselves and play themselves out between human beings.”

Context in Presidential Biographies

Presidential biographies also provided context, countering the tendency to think “that whatever’s going on right now is uniquely disastrous or amazing or difficult,” he said. “It just serves you well to think about Roosevelt trying to navigate through World War II.”

Even books initially picked up as escape reading like the Hugo Award-winning apocalyptic sci-fi epic “The Three-Body Problem” by the Chinese writer Liu Cixin, he said, could unexpectedly put things in perspective: “The scope of it was immense. So that was fun to read, partly because my day-to-day problems with Congress seem fairly petty — not something to worry about. Aliens are about to invade!”

In his searching 1995 book “Dreams From My Father,” Mr. Obama recalls how reading was a crucial tool in sorting out what he believed, dating back to his teenage years, when he immersed himself in works by Baldwin, Ellison, Hughes, Wright, DuBois and Malcolm X in an effort “to raise myself to be a black man in America.” Later, during his last two years in college, he spent a focused period of deep self-reflection and study, methodically reading philosophers from St. Augustine to Nietzsche, Emerson to Sartre to Niebuhr, to strip down and test his own beliefs.

To this day, reading has remained an essential part of his daily life. He recently gave his daughter Malia a Kindle filled with books he wanted to share with her (including “One Hundred Years of Solitude,” “The Golden Notebook” and “The Woman Warrior”). And most every night in the White House, he would read for an hour or so late at night — reading that was deep and ecumenical, ranging from contemporary literary fiction (the last novel he read was Colson Whitehead’s “The Underground Railroad”) to classic novels to groundbreaking works of nonfiction like Daniel Kahneman’s “Thinking, Fast and Slow” and Elizabeth Kolbert’s “The Sixth Extinction.”

Photo

“The Underground Railroad” by Colson Whitehead.Credit
Patricia Wall/The New York Times

Such books were a way for the president to shift mental gears from the briefs and policy papers he studied during the day, a way “to get out of my own head,” a way to escape the White House bubble. Some novels helped him to better “imagine what’s going on in the lives of people” across the country — for instance, he found that Marilynne Robinson’s novels connected him emotionally to the people he was meeting in Iowa during the 2008 campaign, and to his own grandparents, who were from the Midwest, and the small town values of hard work and honesty and humility.

Other novels served as a kind of foil — something to argue with. V. S. Naipaul’s novel “A Bend in the River,” Mr. Obama recalls, “starts with the line ‘The world is what it is; men who are nothing, who allow themselves to become nothing, have no place in it.’ And I always think about that line and I think about his novels when I’m thinking about the hardness of the world sometimes, particularly in foreign policy, and I resist and fight against sometimes that very cynical, more realistic view of the world. And yet, there are times where it feels as if that may be true.”

Writing was key to his thinking process, too: a tool for sorting through “a lot of crosscurrents in my own life — race, class, family. And I genuinely believe that it was part of the way in which I was able to integrate all these pieces of myself into something relatively whole.”

A Writer of Short Stories

Mr. Obama taught himself to write as a young man by keeping a journal and writing short stories when he was a community organizer in Chicago — working on them after he came home from work and drawing upon the stories of the people he met. Many of the tales were about older people, and were informed by a sense of disappointment and loss: “There is not a lot of Jack Kerouac open-road, young kid on the make discovering stuff,” he says. “It’s more melancholy and reflective.”

That experience underscored the power of empathy. An outsider himself — with a father from Kenya, who left when he was 2, and a mother from Kansas, who took him to live for a time in Indonesia — he could relate to many of the people he met in the churches and streets of Chicago, who felt dislocated by change and isolation, and he took to heart his boss’s observation that “the thing that brings people together to share the courage to take action on behalf of their lives is not just that they care about the same issues, it’s that they have shared stories.”

This lesson would become a cornerstone of the president’s vision of an America where shared concerns — simple dreams of a decent job, a secure future for one’s children — might bridge differences and divisions. After all, many people saw their own stories in his — an American story, as he said in his keynote address at the 2004 Democratic National Convention possible “in no other country on Earth.”

Photo

President Obama reading “Where the Wild Things Are” to children at the White House in 2014.Credit
Doug Mills/The New York Times

In today’s polarized environment, where the internet has let people increasingly retreat to their own silos (talking only to like-minded folks, who amplify their certainties and biases), the president sees novels and other art (like the musical “Hamilton”) as providing a kind of bridge that might span usual divides and “a reminder of the truths under the surface of what we argue about every day.”

He points out, for instance, that the fiction of Junot Díaz and Jhumpa Lahiri speaks “to a very particular contemporary immigration experience,” but at the same time tell stories about “longing for this better place but also feeling displaced” — a theme central to much of American literature, and not unlike books by Philip Roth and Saul Bellow that are “steeped with this sense of being an outsider, longing to get in, not sure what you’re giving up.”

Mr. Obama entered office as a writer, and he will soon return to a private life as a writer, planning to work on his memoirs, which will draw on journals he’s kept in the White House (“but not with the sort of discipline that I would have hoped for”). He has a writer’s sensibility — an ability to be in the moment while standing apart as an observer, a novelist’s eye and ear for detail, and a precise but elastic voice capable of moving easily between the lyrical and the vernacular and the profound.

He had lunch last week with five novelists he admires — Dave Eggers, Mr. Whitehead, Zadie Smith, Mr. Díaz and Barbara Kingsolver. He not only talked with them about the political and media landscape, but also talked shop, asking how their book tours were going and remarking that he likes to write first drafts, long hand, on yellow legal pads.

Mr. Obama says he is hoping to eventually use his presidential center website “to widen the audience for good books” — something he’s already done with regular lists of book recommendations — and then encourage a public “conversation about books.”

“At a time,” he says, “when so much of our politics is trying to manage this clash of cultures brought about by globalization and technology and migration, the role of stories to unify — as opposed to divide, to engage rather than to marginalize — is more important than ever.”

Correction: January 16, 2017

An earlier version of a photo caption with this article misstated when a photo of President Obama in the Oval Office was taken. It was taken in 2012, not Friday.