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.”

Image “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.”