Edinburgh Castle was not built in a single campaign. Its development spanned approximately 400 years, from the 12th to the late 16th century.
King David I established the first royal fortress on Castle Rock around 1130, including St. Margaret's Chapel, the oldest surviving building in Edinburgh.
Successive wars of independence against England saw the castle repeatedly damaged and rebuilt. David's Tower and the Great Hall were added.
Under the Stewart monarchs, the castle became a royal palace. The final major addition, the Half Moon Battery, was completed in 1588, giving the castle its distinctive eastern profile.
Later centuries saw military barracks, prisons, and war memorials added. Today, it's a historic site, military garrison, and Scotland's most-visited paid attraction.