linguistic:voice_change, linguistic:paraphrasing
2020–2022: Final years

Federer began his 2020 season at the Australian Open, where he reached the semifinals after saving seven match points in his five-set quarterfinal win over Tennys Sandgren. Federer then lost his semifinal match to Djokovic in straight sets, having sustained a groin injury earlier in the tournament. In February, Federer underwent arthroscopic surgery for a right knee injury and subsequently withdrew from the Dubai Championships, Indian Wells, Miami Open and the French Open to give time for his knee to recover for the grass season. On 10 June, due to a setback from his initial rehabilitation from the knee injury, Federer announced that he had to have an additional arthroscopic procedure on his right knee, vowing to return in 2021. This was only the second year in Federer's career since he won his first title that he finished without a title.

In January 2021, Federer withdrew from the Australian Open due to still recovering from knee surgery and strict COVID-19 quarantine measures in Australia. On 8 March, Novak Djokovic surpassed him for the most career weeks spent as the ATP number 1 ranked player. On 10 March, he made his return to the ATP Tour at the Qatar Open, where he won his first ATP match in 14 months against Dan Evans before losing to Nikoloz Basilashvili in the quarterfinals. At the French Open, Federer withdrew from the tournament before his fourth-round match citing knee problems, giving a walkover to Matteo Berrettini. In Halle, he lost in the second round to Félix Auger-Aliassime, with their 19-year age difference being the biggest in Federer's 1,521 career matches.

At Wimbledon, the nearly 40-year-old Federer became the oldest Wimbledon quarterfinalist in the Open Era, breaking the record held by Ken Rosewall, but he was then upset by 14th seed Hubert Hurkacz in straight sets. This was the first time in 19 years at Wimbledon he had lost in straight sets, and only the second time he had lost a set 6–0 in the 21st century (the previous occasion was against Nadal in the 2008 French Open final). On 15 August, Federer announced that he underwent another knee surgery after a further injury during the grass-court season. He withdrew from the US Open, but he hoped to make a return to the tour in 2022.

Federer did not play in a singles tournament after Wimbledon 2021, and dropped out of the top 50 on 13 June 2022. On 11 July 2022, he became unranked for the first time since his professional debut. However, Federer announced that he was set to return to the tour at the 2022 Laver Cup in September. On 15 September 2022, he announced his impending retirement from professional tennis on the ATP Tour, noting that the Laver Cup would be his final ATP event. He stated that he "will play more tennis in the future, of course, but just not in Grand Slams or on the tour." His final match resulted in a three-set loss in doubles partnering long-time rival and friend Rafael Nadal against Jack Sock and Frances Tiafoe. The match was his 1750th on the tour.