BETHESDA, Md. — President Obama stood outside the room, rubbed sanitizer on his hands, set his face into a smile and knocked on the door.
No one answered. He looked at the hospital floor polished to a sheen and knocked again. Still no answer. So Mr. Obama turned the knob and gently pushed his way inside.
“Hello? Jeremy, what’s going on?” Maj. Jeremy Haynes remembers the president saying as he came into his room at Walter Reed National Military Medical Center two years ago.
It was the first of several visits the president paid Major Haynes, an Army officer who was told he would never walk, feel below his waist or have children again after his spine was hit by a Taliban bullet in Afghanistan. The visits, Major Haynes said, “were truly inspiring to me” and gave him hope for the life ahead of him.
On Tuesday, for his 23rd and probably last time as president, Mr. Obama will helicopter to the military hospital to spend another afternoon with the wounded from Afghanistan and Iraq. The visit is likely to unfold much as Major Haynes and hospital officials described the ones the president paid to him.
Mr. Obama will arrive at the hospital in suburban Maryland on Marine Onewith a minimum of ceremony, having memorized the names of the wounded he will visit from a list he received the night before. At a side entrance to the hospital, a military aide will update him on their conditions. If he visits those still hospitalized, he will climb the stairs to 4 West and 4 Center, known as the soldiers ward. After greeting the doctors and nurses on duty, he will begin his rounds with a knock. If instead he visits the physical therapy center, he will wander one giant room filled with exercise machines and patients learning to live without limbs.
For Mr. Obama, who has served as a wartime commander longer than any of his predecessors, meeting with the wounded and their families is among the most sacred duties of his presidency. He rarely talks about his trips to Walter Reed, but his aides say that they have affected him deeply.
David Axelrod, Mr. Obama’s longtime political aide, said the president often returned to the White House from Walter Reed, first when it was in Washington and later after it had merged with Bethesda Naval Hospital, in a somber mood. After one such trip, he recalled, Mr. Obama described a young woman attending to her newlywed husband, whose body was shattered and head terribly wounded.
“‘You want to be upbeat and encouraging,’ I remember him saying,” Mr. Axelrod said. “‘But they’re just kids starting out, and I looked at his wife’s face and you could see her struggling with what this would mean for the rest of their lives. It’s really hard.’”
In his first two years in office, as the wars in Iraq and Afghanistan raged and there were many wounded, Mr. Obama’s trips to Walter Reed were three- and four-hour slogs during which he donned fresh hospital gowns and gloves outside every fifth room to see patients clinging to life days or weeks after being blown apart. He returned to the White House visibly drained, aides said.
More recently, he has done push-ups and other exercises with newly minted civilians who, instead of struggling to live, are trying to find ways of coping without arms, legs or equilibrium months and years after being wounded.
“The first term, our visits would last for hours because there would be 25, 50, 75 folks that we’d be seeing, going room to room, many with devastating injuries,” Michelle Obama, who has made her own trips to Walter Reed, said recently. “And now, today, just last week he went to visit, and he was there for 30 minutes because there are fewer of our men and women who are being injured in war.”
The afternoon excursions from the White House are in many ways the counterpoint to his 15 trips offering condolences after mass shootings, when he has openly grieved with families, tears on his face. At Walter Reed, his goal has been to thank and uplift the wounded and their families, whose sacrifices he sees as almost holy and among whom expressions of grief are often unwelcome.
“If you are coming into this room with sorrow or to feel sorry for my wounds, go elsewhere,” read one handwritten sign outside a soldier’s door, now framed and installed on the soldiers ward.
Reggie Love, a former aide to Mr. Obama who accompanied him on nearly all of his trips to military hospitals in the first three years of the administration, said the president was good at reading the rooms he entered. Not everyone wanted an upbeat message.
“Sometimes the people he met didn’t have any questions for him or really anything to say,” Mr. Love said. “Sometimes, they just needed a hug.”
Some of the soldiers whom Mr. Obama has visited are more grievously wounded than those seen by any modern president, as improved technology has saved people who even five years ago would have died on the battlefield. The shock of repeatedly seeing such devastating injuries can affect someone’s psyche far more than flag-draped coffins, psychologists say.
“Every time I visit Walter Reed, every time I visit Bethesda, I’m reminded of the wages of war,” Mr. Obama said at Fort Campbell, Ky., in 2011.
Robert M. Gates, the former defense secretary, wrote in his memoir “Duty” that seeing the wounded and attending funerals took such an emotional toll that he had to resign. Critics see another effect. Over the course of his presidency, Mr. Obama has become increasingly unwilling to commit troops to wars in places like Libya, Syria and Iraq.
Eliot A. Cohen, an official in the George W. Bush administration who is now professor of strategic studies at Johns Hopkins University, said that Mr. Obama’s trips to Walter Reed may have been the reason, and that future presidents should avoid the visits.
“A president has to be psychologically prepared to send people into harm’s way and to get a good night’s sleep,” Mr. Cohen said. “And anything they do that might cripple them that way means they’re not doing their job.”
Mr. Obama has rejected such criticism, saying his rounds at Walter Reed have highlighted the risks of war but have not stopped him from ordering troops into battle when needed.
His message to the wounded is always the same.
“He walked in and said, ‘Tim, thank you for what you’ve done. I appreciate your sacrifice, and the country is indebted to you,’” said Timothy Payne, who stepped on a bomb in Afghanistan in 2011 and lost both legs. “And then he shook my hand and gave me one of those presidential coins.”
“And then he said, ‘What happened?’ And I said, ‘Well, I got blown up,’ and we both laughed,” Mr. Payne said.
Spouses, parents and children are often present, and Mr. Obama always addresses them by their first names. He sometimes hugs wives, but if a mother is there he invariably says, “And moms get hugs,” and embraces her.
After the greetings, Mr. Obama sometimes calls in a military aide so he can award a Purple Heart or other citation. He asks if they have any questions or concerns and calls in another aide to take notes and follow through. The most common question deals with retiring from active duty, a laborious and often frustrating process for the wounded.
The visits end with Mr. Obama’s signing unit flags, books and anything else presented to him, and with a photographer taking group and paired shots. Sometimes families ask to have photos taken with their own cellphones, which Mr. Obama hands over to his photographer.
In June, Mr. Obama visited the hospital’s physical therapy room, where amputees learn to walk again. One double-amputee gave Mr. Obama a push-up challenge, and Mr. Obama promptly shed his suit jacket, dropped to the floor and reeled off more than 20. Still wearing dress shoes, he joined another in jumping onto a 30-inch box.
“I can’t even put into words how impressed I was,” said Lt. Cmdr. John Terry, known as Jae, an amputee whose photo of doing lunges with Mr. Obama is among his most treasured possessions. “I will remember that day until I die.”
Not every severely wounded patient at Walter Reed meets the president. Some miss him by chance. A few refuse because they disagree with the president’s politics.
But even some of the president’s critics say his presence ennobled their injuries and made them feel part of a larger plan.
As he buckled his two stumps into prosthetic legs at the hospital one day recently, Edward Klein, known as Flip, a now retired Army major, acknowledged that “I wasn’t a big fan of his politically.”
But, he added: “Meeting the president added a feeling of legitimacy and recognition for what I did.”