The five-time champion who is defending the title and needs as many matches as possible before the August 26 start of the US Open, won his seventh career match against German friend Philipp Kohlschreiber 6-3, 7-6 (9/7).
The fifth-ranked Swiss felt in his element as he played the tournament for the 13th time, improving his record to 31-10 this season.
"I think it was a match where I had to sort of just fight to come through and hope to get over the finish line," Federer said.
"I was playing really well at times, and then sometimes it was maybe a bit up and down," he said.
"Assessing the performance overall, I'm very happy. It's good to be back and playing pain free," Federer said.
"I don't know, my mind's good," he said.
"I was in a good place while I was playing, so it felt nice to win at the end."
Spanish third seed David Ferrer joined Federer in the third round with a 7-6 (7/5), 3-6, 6-4 victory over American Ryan Harrison.
Montreal finalist Milos Raonic struggled in the opening set against Jack Sock, but found his rhythm for a 3-6, 6-4, 6-3 win and a date on Wednesday with Janko Tipsarevic.
American Sloane Stephens snatched her second major scalp of the season as she toppled former champion Maria Sharapova in the second round at Cincinnati.
Stephens on Tuesday rallied to beat the world number three from Russia 2-6, 7-6 (7/5), 6-3, bringing Sharapova's injury return to an abrupt end in this combined WTA and ATP Masters hardcourt tournament.
In women’s action, Maria Sharapova — who enjoyed a first-round bye — was knocked out of the second round by American Sloane Stephens, who snatched her second major scalp of the season.
Stephens rallied to beat the world number three from Russia 2-6, 7-6 (7/5), 6-3, bringing Sharapova's injury return to an abrupt end in this combined WTA and ATP Masters hardcourt tournament.