Nadal, 31, saw off Argentine lucky loser Leonardo Mayer6-7 (3/7), 6-3, 6-1, 6-4, taking his record over the worldnumber 59 from Buenos Aires to 4-0.
He will face Ukraine's Alexandr Dolgopolov, against whomhe is 6-2, for a place in the quarter-finals. Five-time champion Federer brushed aside 31st seedFeliciano Lopez 6-3, 6-3, 7-5 to take his career record against the Spaniard, playing a 63rd successive Grand Slam, to 13-0.
Next up for Federer is Philipp Kohlschreiber, who heleads 11-0. Nadal had dropped the first set of his second-round match against Japan's Taro Daniel before winning in four. Saturday was almost a carbon copy with the 15-time major winner unable to convert any of six points in the opener.
But the match turned in the 10-minute seventh game of the second set when, on his 14th break point of the encounter, Nadal finally smashed through.
"It was tough. It took 14 break points -- that's not a good figure. But I was there mentally and fought a lot at theright moments," said Nadal under the Arthur Ashe roof as rainfell outside.
Federer had needed back-to-back five-setters to defeat Frances Tiafoe and Mikhail Youzhny in his first two rounds. However, on Saturday, he swept past Lopez to reach thefourth round for the 16th time.
"I'm very happy to get through. It's a great feeling to play out here," said Federer.
"I struggled in the first two rounds but tonight I playeda very clean match."
Kohlschreiber, the German 33rd seed, eliminated Australia's John Millman 7-5, 6-2, 6-4.
Austrian sixth seed Dominic Thiem defeated France's Adrian Mannarino 7-5, 6-3, 6-4 to make the last 16 for thethird time in four years.
Thiem next faces 2009 champion Juan Martin del Potro of Argentina, who put out Spain's Roberto Bautista Agut 6-3, 6-3,6-4. Russia's Andrey Rublev became the second teenager in the last 16 when he beat Bosnia's Damir Dzumhur 6-4, 6-4, 5-7, 6-4.
Rublev, just 19, faces Belgian ninth seed David Goffin, who progressed when 2016 semi-finalist Gael Monfils retired with a right knee injury.
Meanwhile, Fognini was kicked out of the tournament formaking foul-mouthed comments to female umpire Louise Engzellduring his first-round loss to Stefano Travaglia.
Fognini and compatriot Simone Bolelli had reached thethird round of the men's doubles but tournament organizersaxed him from the event. Fognini, the world number 26, was also fined $24,000.
Pliskova saves match point
Women's top seed Karolina Pliskova saved a match point to defeat China's Zhang Shuai, hanging on to her world number one spot in the process. Top seed Pliskova, the runner-up in 2016, triumphed 3-6,7-5, 6-4 but was forced to save a match point in the 10th game of the second set and recover from a break down in the decider.
"I was match point down and I thought I haven't tried many forehand winners down the line. That's what I did. I maynot have got another chance," said the 25-year-old, who will next face Jennifer Brady of the United States.
Brady has just seven wins on the tour this year, but all have come at the Slams. Had she lost on Saturday, Pliskova would also have been guaranteed to lose her world number one ranking to either Wimbledon champion Garbine Muguruza or Elina Svitolina.
Ukraine fourth seed Svitolina stayed in contention with a6-4, 7-5 win over Shel by Rogers of the United States. Russia's Daria Kasatkina reached the last 16 of a majorfor the first time by seeing off French Open champion Jelena Ostapenko, the 12th seed, 6-3, 6-2.