Federer, 30, reached the semi-finals at the recent US Open, where he squandered two match points before losing to Novak Djokovic, and then flew straight to Sydney to play for Switzerland in their Davis Cup tie with Australia.
The 16-time grand slam champion said: "After consultation with my team, I've unfortunately decided to pull out of the Shanghai Masters in order to take some necessary time to rest and recuperate after a long summer.
"I have some nagging injuries that I need to address and I look forward to returning to the ATP World Tour as soon as possible.
"I have very fond memories of Shanghai so I will miss this amazing tournament and all my loyal Chinese fans, but I look forward to returning to China next fall."
Federer is scheduled to return to action at the end of October at his hometown tournament in Basle.