Roger Federer's 2012 tennis season officially began on 2 January with the start of the 2012 ATP World Tour. Federer began the year with a semifinals finish at the Australian Open after a four-set loss to archrival Rafael Nadal. He recovered from his loss with three consecutive titles at the ABN AMRO World Tennis Tournament, the Dubai Duty Free Tennis Championships, and the BNP Paribas Open. He won his fourth title at the Mutua Madrid Open on blue clay, becoming the only person to win a title on blue clay in ATP history. By doing so, he regained the #2 ranking from Rafael Nadal At the French Open, Federer played four tough matches before he was ousted by Djokovic in the semifinals.

The highlight of Federer's season came at the 2012 Wimbledon Championships, where he made a dramatic comeback at two sets down in the third round versus Julien Benneteau, and carried momentum from this victory to win a seventh Wimbledon title over native British favorite Andy Murray, in the process tying Pete Sampras' record of Wimbledon titles and clinching his record-setting seventeenth Grand Slam. His win at Wimbledon also saw him climb past Djokovic to return to the World No. 1 ranking, and saw him breaking Sampras' record of weeks at World No. 1. Federer went on to win his first Olympic singles medal at the 2012 London Olympics, winning silver.

Federer then won his third Masters 1000 title of the season and his twenty-first overall at the Western & Southern Open. He was upset in the quarterfinals of the US Open by Tomáš Berdych. Federer finished his season at the ATP World Tour Finals, where he lost to Djokovic in a tight final. Federer ended his season with six calendar titles, a Grand Slam title, 3 Masters 1000 titles and an Olympic silver medal. Federer also represented Switzerland in the Davis Cup, and helped Switzerland to advance to the 2013 Davis Cup World Group.

The 2012 season was a return to form for Federer. He had his most match wins (71) since 2006, and his highest winning percentage (86%) and number of titles won (6) since 2007. The two most significant accomplishments of his season included winning a record seventeenth Grand Slam title (his first since the 2010 Australian Open) and returning to World No. 1.

Year summary

Early hard court season and Australian Open

Qatar Open

Federer began his ATP World Tour season at the Qatar Open, where he was defending his title. After straight-set victories over 2011 finalist Nikolay Davydenko and qualifier Grega Žemlja, Federer won a hard-fought, error-prone match over eighth-seeded Andreas Seppi. Federer was scheduled to play Jo-Wilfried Tsonga in a rematch of the previous year's semifinal, but was forced to withdraw due to a back spasm problem. This marked only the second time in Federer's career (after the 2008 Paris Masters) that he withdrew from a tournament because of injury.

Australian Open Federer next traveled to Melbourne for the first Grand Slam of the season, the Australian Open. The Swiss advanced through the first four rounds without the loss of a set, starting his campaign by defeating qualifier Alexander Kudryavtsev, receiving a walkover into the third round when Andreas Beck withdrew with a lower back injury prior to their second round match, and beating Ivo Karlović to improve to a 10–1 head-to-head record against the Croat. Federer then faced Australian teenager Bernard Tomic and downed him in less than two hours to extend his record streak of Grand Slam quarterfinals consecutive appearances to 31. In the quarterfinals, Federer faced world no. 11 Juan Martín del Potro in his 1000th career match. It was their first meeting in a major tournament since Del Potro defeated Federer in five sets in the 2009 US Open men's final. As the tight match slowly progressed, Federer took control and flew by del Potro in straight sets. With his win, Federer becomes the first player at age 30 and over to reach the Australian Open semifinals since Andre Agassi, and extends his match winning streak (started in September 2011) to 24 consecutive victories. Federer played world no. 2 and archrival Rafael Nadal in the semifinals. He opened up the match by winning the first set, but ultimately lost momentum and dropped the next three sets after a failed attempt to get back in the match by taking the third set. Federer's loss to Nadal saw his winning streak of 24 consecutive matches end and his record against Nadal slip to 9–18.

Rotterdam Open Federer went to the ABN AMRO World Tennis Tournament in Rotterdam for the first time since he won in 2005. He faced Frenchman Nicolas Mahut in the first round and defeated him in straight sets. He then received a walkover against Mikhail Youzhny, and then defeated Jarkko Nieminen in the quarterfinals in two tight sets. In the semifinals, Federer dropped his opening set to an aggressive Nikolay Davydenko, but rallied to win the match in three sets. He beat Juan Martín del Potro in the final to clinch his second title in Rotterdam.

Dubai Tennis Championships Federer next played in the Dubai Tennis Championships. He played Frenchman Michaël Llodra in the first round and defeated him in straight sets after a tight second set went to a tiebreak. He then faced Feliciano López and, after a slow start, defeated him in straight sets. He next played Mikhail Youzhny and flew to a straight-sets victory after dropping only fourteen points on serve. In the semifinals, he defeated Juan Martín del Potro in two tight tiebreaks. He beat Andy Murray in the final to clinch his fifth title in Dubai, his second consecutive title, and his second title of the year. He also finished the tournament without dropping a set.

Indian Wells Masters

Immediately following his win at Dubai, Federer began his trip to the United States with an appearance at the BNP Paribas Showdown, playing an exhibition match against Andy Roddick. After two very tight sets, Federer was defeated by Roddick in the second-set tiebreak.

Federer next participated in the Indian Wells Masters in Indian Wells, California. Federer had come down with flu-like symptoms prior to his opening match due to a virus that had spread around the players at the beginning of the tournament. After receiving a bye into the second round, he faced American qualifier Denis Kudla, and dispatched him in straight sets. He next faced young up-and-coming Canadian Milos Raonic. Raonic grabbed a tight first set after winning the set tiebreaker, but Federer came back strong with two break points in the second set to level the match. Federer found a break point late in the third set and held to secure a close three-set win over Raonic. Still recovering from his illness, Federer played Brazilian Thomaz Bellucci, who had received a walkover from the third round, the day after his match with Raonic. Bellucci took advantage of a shaky Federer to win the first set, but Federer found his rhythm and fought back to win the next two sets and the match with two crucial break points, one of which was also match point. Federer then played Juan Martín del Potro for the fourth time in the season in the quarterfinals. After winning three break points throughout the match, Federer defeated del Potro in 69 minutes, earning his 250th career Masters 1000 win. He then faced archrival Rafael Nadal, whom he had last played in his loss in the Australian Open semifinals. Rain delays kept the two rivals off the court for a few hours, but when they began playing, Federer got off to a fast start, securing two break points to win the set with ease. He then capitalized on two more break points to give himself a big lead. After fending off a late comeback by Nadal and waiting out a short rain delay after drawing match point, Federer sealed the match with an ace, recording his tenth career win over Nadal. In the final, Federer met American John Isner, who had beaten him in their last meeting in the Davis Cup, and defeated him in straight sets, clinching a record-tying 19th Masters 1000 title.

Miami Masters Federer next played at the Miami Masters. Federer opened in the second round against wildcard American Ryan Harrison after taking a bye in the first round. Federer controlled much of the match and avoided a late comeback by Harrison to win in straight sets after a second set tiebreak. He next played perennial rival Andy Roddick in the third round. Federer dropped the first set tiebreak, but came back strong with three break points in the second set. The third set saw Roddick save four break points in the second game and pull momentum from Federer, who gave up a break in the next game. Federer's serve faltered, and Roddick held his next four service games to win the match and defeat Federer for only the third time in his career, the first time since he last defeated Federer at the 2008 Miami Masters. This loss ended Federer's 16-match winning streak.

Clay court season and French Open

Madrid Open

Federer started off his clay court season with the Madrid Open. He received a bye to the second round, where he faced Milos Raonic. After dropping the first set, Federer saved seven break points in the next two sets to hold off Raonic and win the match in the third-set tiebreak. Federer then played Frenchman Richard Gasquet in the third round, and flew to a win in less than an hour, winning in straight sets. In the quarterfinals, Federer defeated Spaniard David Ferrer in straight sets, losing only six points on his serve, and extended his undefeated record against Ferrer. He defeated Janko Tipsarević in the semifinals in straight sets in just over an hour, and also extended an undefeated record against him. In clinching a spot in the final, Federer broke Ivan Lendl's record for the most combined Championship Masters Series finals, which includes his finals appearances at Masters 1000 events, and stands alone at 32 finals reached. In his 104th career final, he defeated Tomáš Berdych in three sets after dropping the first set. With his win, he regained the world no. 2 ranking from Spaniard Rafael Nadal. He also won his third Madrid Masters title and tied Nadal's record of 20 ATP World Tour Masters 1000 titles.

Italian Open Federer next played at the Italian Open in Rome. He received a bye into the second round where he met and comfortably beat Carlos Berlocq of Argentina in straight sets. In the third round, he played 2001 champion Juan Carlos Ferrero and defeated him in three sets after Ferrero had won the second set by converting a break. Federer then faced hometown favorite Andreas Seppi in the quarterfinals, but defeated him by a comfortable margin, dropping only three games en route to a straight sets win. Federer next lost to first-seeded Novak Djokovic in the semifinal in straight sets, after failing to gain enough momentum to overcome Djokovic in the second-set tiebreak. As Nadal ultimately won the tournament, Federer dropped to world No. 3 rank.

French Open