"I have to say, when I heard that people actually watch this show, I was actually pretty surprised," the president said as the interview began.
On "Between Two Ferns," Galifianakis typically poses awkward questions, and Mr. Obama was no exception.
"Do you send Ambassador Rodman to North Korea on your behalf?" he asked the president. "I read somewhere that you'd be sending Hulk Hogan to Syria, or is that more of a job for Tanya Harding?"
Galifianakis also asked how it felt to be the "last black president," to which Mr. Obama replied, "Seriously? What's it like for this to be the last time you ever talk to a president?"
Obama's appearance is part of an effort to urge young Americans to sign up for his health care plan.
The Associated Press contributed to this report.