Stirling Castle, located in Stirling, is one of the largest and most important castles in Scotland, both historically and architecturally. The castle sits atop Castle Hill, an intrusive crag, which forms part of the Stirling Sill geological formation. It is surrounded on three sides by steep cliffs, giving it a strong defensive position. Its strategic location, guarding what was, until the 1890s, the farthest downstream crossing of the River Forth, has made it an important fortification in the region from the earliest times.
Most of the principal buildings of the castle date from the fifteenth and sixteenth centuries. A few structures of the fourteenth century remain, while the outer defences fronting the town date from the early eighteenth century.
Before the union with England, Stirling Castle was also one of the most used of the many Scottish royal residences, very much a palace as well as a fortress. Several Scottish Kings and Queens have been crowned at Stirling, including Mary, Queen of Scots, in 1542, and others were born or died there. There have been at least eight sieges of Stirling Castle, including several during the Wars of Scottish Independence, with the last being in 1746, when Bonnie Prince Charlie unsuccessfully tried to take the castle.
Castle Hill, on which Stirling Castle is built, forms part of the Stirling Sill, a formation of quartz-dolerite around 350 million years old, which was subsequently modified by glaciation to form a "crag and tail". It is likely that this natural feature was occupied at an early date, as a hill fort is located on Gowan Hill, immediately to the east.
The Romans bypassed Stirling, building a fort at Doune instead, but the rock may have been occupied by the Maeatae at this time. It may later have been a stronghold of the Manaw Gododdin, and has also been identified with a settlement recorded in the 7th and 8th centuries as Iudeu, where King Penda of Mercia besieged King Oswy of Bernicia in 655. The area came under Pictish control after the defeat of the Northumbrians at the Battle of Dun Nechtain thirty years later. However, there is no archaeological evidence for occupation of Castle Hill before the late medieval period.
The first record of Stirling Castle dates from around 1110, when King Alexander I dedicated a chapel here. It appears to have been an established royal centre by this time, as Alexander died here in 1124. During the reign of his successor David I, Stirling became a royal burgh, and the castle an important administration centre. King William I formed a deer park to the south-west of the castle, but after his capture by the English in 1174, he was forced to surrender several castles, including Stirling and Edinburgh, under the Treaty of Falaise. There is no evidence that the English actually occupied the castle, and it was formally handed back by Richard I of England in 1189. Stirling continued to be a favoured royal residence, with William himself dying there in 1214, and Alexander III laying out the New Park, for deer hunting, in the 1260s.