Nadal breezed past Borna Coric of Croatia 6-1, 6-2 to advance to the third round, while Federer routed Canadian Peter Polansky, 6-2, 6-1 in 53 minutes.
Nadal, a three-time Rogers Cup winner who is back in the hunt for the No. 1 ranking after winning his 10th French Open title this year, will play Canadian teenager Denis Shapovalov, who downed 2009 U.S. Open champion Juan Martin De Potro 6-3, 7-6 (4) in a second-round match on a gusty Wednesday afternoon.
The 18-year-old Shapovalov became the youngest player to reach the round of 16 of a Master Series tournament since Nadal in 2004 at Miami.
Federer, a two-time Rogers Cup champion ranked third in the world, has had a surprise resurgence this season by posting his 18th and 19th career Grand Slam wins at the Australian Open and Wimbledon. He played his first match of the hardcourt season that leads to the U.S. Open.
"I think this tournament I'm trying to play with confidence that I gained through the grass-court season," Federer said. "I have to adjust my game a little bit just because the bounce of the ball is so much higher here than at Wimbledon, and there's wind, which in Wimbledon we didn't have much of.
"It's just really to see how it goes this week, and then learn from this week, how I need to then play in Cincinnati (next week) and the U.S. Open."
The Swiss star, who turned 36 on Tuesday, next faces Spain's David Ferrer, a 7-6 (7), 3-6, 6-1 winner over 15th-seeded American Jack Sock.
Polansky, ranked No. 116 in the world after some strong results in challenger events, upset No. 75 Vasek Pospisil of Canada in the first round on Monday.
It was his second meeting with Federer. At the 2014 Rogers Cup, he lost 6-2, 6-0.
"Even though I lost, this is one of the most memorable experiences of my life along with the match I played against him in Toronto," Polansky said. "His transition from the baseline to the net, it's a joke.
"You blink and he's at the net. You hit balls pretty hard at him and he's handling them like it's no problem. Guys I'm used to playing, if I hit really hard, they'll kind of block it but he's constantly moving forward like a freight train."
Sixth seed Milos Raonic, another Canadian, lost 6-4, 6-4 to Frenchman Adrian Mannarino in his opening match while playing through a left wrist injury that flared up this week.
In other results, third-seeded Dominic Thiem of Austria was upset 6-4, 6-7 (7), 7-5 by Argentina's Diego Schwartzman, and fifth-seeded Kei Nishikori of Japan, a finalist last year, was ousted 6-7 (4), 7-6 (7), 7-5 by Gael Monfils. It was the Frenchman's first win in four meetings with Nishikori.
Seventh-seeded Bulgarian Grigor Dimitrov topped German Mischa Zverev 6-3, 3-6, 6-3. No. 12 Roberto Bautista Agut of Spain downed American Ryan Harrison 7-5, 6-2, and Robin Haase of the Netherlands defeated lucky loser Ernesto Escobedo 6-4, 6-1.