Tokyo 2020 will mark Federer's fifth appearance at the Olympics, having first featured at Sydney 2000.
Federer will require an exemption to compete in Tokyo as he is yet to play in the Davis Cup for Switzerland in the current Olympic cycle that began after the Rio Olympics in 2016.
"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 said, via the Olympic Channel.
Federer has never won the Olympic gold medal in the singles, although he did pick up the silver in the defeat to Andy Murray in 2012.
"That's what people will say: "That's why he's playing, he needs to go and get the gold to fill out his trophy cabinet", Federer told CNN.
"Every Olympic games has been very, very special to me", Federer said during the announcement.
"I just figured it was an organic place to do that", he said, "so I am very happy to announce it here".
"If it is another gold great. if the house comes down it will just be too much, it will be insane and I hope I will be ready for it". "I just felt like this, for me, is something I would like to do if I am healthy".
Switzerland's Olympics squad for Tokyo 2020 will include Roger Federer, with the 38-year-old confirming his plan to play at the Games.
Roger Federer, to many the greatest tennis player of all time, has built a career based on being ice cool when the heat is on but even the great Swiss couldn't control his temper during a topsy turvy match in the quarter finals of the Shanghai Open as he went down in 3 sets to German star Alexander Zverev. The tennis competition begins two weeks after Wimbledon and finishes four weeks prior to the U.S. Open.
"I'd like to reach the final and go further than in Beijing".
"Last time I was injured and not in good condition". I don't want to take pressure off myself, I can handle the pressure, it's not a problem - I just want to give it the best shot I have and see if I can make another medal.