The palace said the operation on 91-year-old Prince Philip - which will take place on Friday - was pre-planned and comes after "abdominal investigations" that were carried out over the past week.
"He is in good spirits," said a spokeswoman for the palace. She declined to elaborate on Philip's condition or when the decision was made to operate, saying only that the queen's husband is expected to be in the London Clinic for up to two weeks.
The London Clinic - a private hospital and longtime favorite for celebrities and royals in need of treatment - declined to comment.
Philip was driven by car to the hospital shortly after attending a Buckingham Palace garden party hosted by his wife. Footage from the party showed the queen's husband smiling and chatting with guests as he walked around the garden.
Prime Minister David Cameron sent Philip his best wishes via Twitter, writing that he hopes the queen's husband has a "swift recovery."
After pulling out of an event earlier this week because of illness, Philip later attended a service to mark the 60th anniversary of the queen's coronation.
Philip turns 92 on June 10. His health was in the spotlight last summer when he spent almost a week in the hospital after a recurrence of a bladder infection.
He also has been treated for heart disease in recent years, and along with the queen has cut back on lengthy overseas travel. Still, the royals maintain active public schedules inside Britain.
The queen is expected to carry out her scheduled engagements as planned on Friday, which include a visit to the new BBC studios in central London.