The 40-year-old Swiss, a 20-time Grand Slam champion, had two knee operations last year.
In a video post on Instagram, Federer said he hoped the surgery would give him “a glimmer of hope” to return to action.
He was knocked out in the quarter-finals at Wimbledon in July and then missed the Tokyo Olympics.
“I’ll be on crutches for many weeks, and also out of the game for many months,” Federer, who turned 40 a week ago, said on Sunday evening.
“It’s going to be difficult in some ways but, at the same time, I know it’s the right thing to do because I want to be healthy, I want to be running around later as well again.
“I also want to give myself a glimmer of hope to return to the tour in some shape or form.
“I am realistic – I know how difficult it is at this age right now to do another surgery and try it.
“But I want to be healthy. I will go through the rehab process with a goal, while I’m still active, which I think is going to help me during this long period of time.”
After losing to Poland’s Hubert Hurkacz at Wimbledon, Federer – now ranked number nine in the world – told reporters he was unsure whether he would play at SW19 again.
In the past two years, he has seen his Grand Slam titles tally equalled twice – first by Spain’s Rafael Nadal at the 2020 French Open and then by Serbia’s Novak Djokovic, who won a 20th major at Wimbledon 2021.
Federer had two operations on his right knee in 2020 after the Australian Open, before returning to the Tour in Doha in March. (Courtesy BBC)