The festival, which has been cancelled for the last two years due to the pandemic, returns with the former Beatle as the headliner for Saturday, 25 June.
This will be Sir Paul's second time on the Pyramid stage, the last time being in 2004.
It comes a week after he celebrated his 80th birthday and more than 60 years of making music.
In May 2022, he said his performance at the popular festival will be full of hits from his time in the Beatles and Wings, and some of his most popular solo work.
Sir Paul McCartney said: "The audience have paid good money, have brought their mums and dads and do not want to hear my deep cuts."
The Beatles were signed by Brian Epstein in 1962 and had hits with songs including Hey Jude, She Loves You, Twist And Shout, and All You Need Is Love until they split in 1970.
Sir Paul later formed a new group, Wings, with his wife Linda as one of the members.
Wings went on to have hits with songs including Mull Of Kintyre and James Bond film theme Live And Let Die before they disbanded in 1981.
Sir Paul McCartney's solo career has included high-profile collaborations, including Ebony And Ivory with Stevie Wonder in 1982, The Girl Is Mine with Michael Jackson later that year and more recently FourFive Seconds with Kanye West and Rihanna in 2015.
His performance is expected to attract an exceptionally large crowd and could rival those of the Rolling Stones in 2013 and Adele in 2016.
Meanwhile, Glastonbury 2022 will also host its youngest ever solo headliner, 20-year-old Billie Eilish on Friday night.
Listen to ITV News' entertainment podcast, Unscripted.