The Swiss will be aiming to secure a third medal next year in Tokyo; he struck gold playing alongside Stan Wawrinka in the men's doubles in Beijing in 2008, then collected silver in the singles tournament four years later in London, falling in the final to home favourite Andy Murray.
Federer, 38, also represented his country at the Olympics in 2000, losing out in the bronze-medal match to Arnaud Di Pasquale, and 2004, but missed Rio 2016 while recovering from a knee injury.
The 20-time grand slam champion announced his decision to compete again after an exhibition match against John Isner staged in the host city for next year's Games.
"I've been debating with my team for a few weeks now, months actually, what I should do in the summer time [of 2020] after Wimbledon and before the US Open," he said, according to the Olympic Channel website.
"At the end of the day my heart decided I would love to play the Olympic Games again.
"I carried the flag twice for Switzerland in Athens and Beijing, I've got a gold and a silver, and I would love to play again so I'm very excited."
Federer has won three titles on the ATP Tour this season, while he finished runner-up to Novak Djokovic at Wimbledon after reaching the last four at the French Open.
Photo: Clive Brunskill/Getty Images Caption: Roger Federer and Stan Wawrinka pose with their gold medals at the 2008 Olympic Games.