The German ranked 83rd with one career title had replaced injured Frenchman Jeremy Chardy as the first opponent for the Swiss home hero and world number one.
Federer, who has won five of the last six editions at the St Jakobshalle where he got his start in tennis as a ballboy at the tournament almost two decades ago, needed to work to get past the persistent Becker, whom he beat in their last two meetings, the last in 2010.
“I was well-prepared to play Becker instead of Chardy,” said Federer, bidding for his 77th career title this week and after more than 300 weeks spent as the ATP number one.
“You have to keep the game of these guys in mind, You don’t play them that much but you need to know how they play,”
The winner advanced in just under 90 minutes after a first set which took an hour and fired 10 aces in victory.
But the Swiss didn’t have it all his own way, missing on six break points in the opening set and going down a break in the second before finally settling in, taking charge and running out the winner.
“I don’t know exactly how I changed it around,” said Federer, playing his first match since losing a Shanghai semi-final nine days ago to Andy Murray, sitting out this tournament with a back injury.
“He broke me at 2-3 but I was able to get it straight back. It all went so fast at the end, but the first set was really tough.”
Federer’s win was his 65th of the season against nine losses. He owns an ATP-leading six titles in 2012.
“It is just so great to play at home as world number one after the season I’ve had,” said Federer. “It’s a wonderful feeling to be here playing at the top of my game.
“Sometimes things just all come together.”
Federer is making his 13th appearance in his hometown tournament and now stands 44-7 at the event. Besides his five titles he also played finals in 2000-01 and 2009.
The winner will await an opponent from Brazilian Tomaz Bellucci, finalist at the weekend in Moscow, and Japan’s Go Soeda.
Elsewhere in the first round, Julien Benneteau of France beat Russian Andrey Kuznetsov 4-6, 6-3, 6-3 while Pole Lukasz Kubot advanced over Slovak Lukas Lacko 6-4, 6-4.