The 35-year-old Swiss cruised into the semifinals with a 6-3, 6-4 win on grass against the defending champion from Germany in an hour and six minutes
"It was important to be aggressive off the baseline and make him feel my variation and the power I can bring to the court," Federer said afterward. "And then having good footwork, to see the short ball, the floater, where I can come in and knock it off with a volley. I think I did it very well. I had lots of chances to even go up a double break in the second set.
"I thought I was very calm out there, even in difficult moments. I was calm serving out the first and second sets. Those are always signs for me that things are slowly starting to fall into place nicely."
Federer has yet to drop a set after three matches this week. He boosted his head-to-head record against Mayer to 8-0, with five of those wins coming on grass.
Federer is through to the semifinals in Halle for the 13th consecutive time, with his two quarterfinal losses at the event coming in 2000-2001. He improved his Halle record to 57-6.
Federer will next face 21-year-old Karen Khachanov, who beat fellow Russian Andrey Rublev 7-6 (8), 4-6, 6-3.
Zverev defeated Federer last year in a three-set semifinal and they could meet again in the final.
"It will be interesting," Federer said of Zverev. "He plays a bit different on the serve and the forehand, which is different to the regular forehand technique we see. He's big and strong and seems super excited to be on tour and he's working hard. I don't know him that well yet so it's a match where I'll most likely focus on my own game. Make sure I serve well, because he can go through spells where he can serve big. It could be somewhat similar to how I played today."