The 20-time Grand Slam champion won silver in the singles at London 2012 after claiming doubles gold at Beijing 2008
The 38-year-old stated "if I am healthy, I am coming" when making the announcement in Tokyo after playing an exhibition match against John Isner.
“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,” Federer added.
“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.”
Tokyo 2020 will mark Federer's fifth appearance at the Olympics, having first featured at Sydney 2000. He missed Rio 2016 due to injury.
Federer added: "I checked with the team if it was okay for me to announce it here, while I am actually in the city where the Olympics will take place. I just figured it was an organic place to do that. So I am very happy to announce it, yes.
"Every Olympic Games has been very, very special to me. This is something I would like to do if I am healthy. And that is why I really hope I will be and I cannot wait."
The event at next year's Games falls between two Grand Slams, getting under way two weeks after the men's Wimbledon final.
The men's singles gold-medal match in Tokyo is scheduled for August 2, four weeks before the US Open starts in New York.
World number one Novak Djokovic is among the competitors out to challenge Federer for Olympic gold.
Djokovic, a bronze medallist at Beijing 2008, won the Japan Open earlier this month without dropping a set at Ariake Colosseum - the venue for next year’s Olympics.
"I'll try to be ready for the Tokyo Olympics in great shape," the Serb told reporters.
"Last time I was injured and not in good condition. I’d like to reach the final and go further than in Beijing. I'll fight for the gold medal."