A palace originally built on this spot in the 13th century for the kings of Hungary was reconstructed in the Renaissance style under the supervision of King Matthias during the 15th century. That, in turn, was demolished as Buda was recaptured from the Turks in 1686.
The Habsburg empress Maria Theresa directed the building of a new palace in the 1700s. It was damaged during an unsuccessful attack by revolutionaries in 1849, but the Habsburgs set about building again, completing work in 1905.
Then, near the end of the Soviets' seven-week siege in February 1945, the entire Castle Hill district of palaces, mansions, and churches was reduced to rubble. Decades passed before reconstruction and whatever restoration was possible were completed. Archaeologists were able to recover both the original defensive walls and royal chambers, due in part to still surviving plans and texts from the reigns of Holy Roman Emperor Sigismund and King Matthias.
Freed from mounds of rubble, the foundation walls and medieval castle walls were completed, and the ramparts surrounding the medieval royal residence were re-created as close to their original shape and size as possible. If you want an idea of the Hungarian homelife of Franz Josef and Sissi, however, you'll have to visit the baroque Gödöllő Palace.
Today, the Royal Palace is used as a cultural center. It comprises three main sections set around the Lion Courtyard: the river-facing east wing (A-D) houses the Magyar Nemzeti Galéria (Hungarian National Gallery); the baroque southern wing (E) contains the Vármúzeum és Szent István-terem (Castle Museum and St. Stephen's Hall); and the W-shaped west wing (F) is home to the Országos Széchényi Könyvtár (National Széchenyi Library), which has a copy of more than two million volumes—everything ever published in the Hungarian language—along with well-preserved medieval codices, manuscripts, and even a sound library.