The site of Edinburgh castle dates back a long way - 70 million years in fact. Its prominent position overlooks central Edinburgh atop a rocky volcanic outcrop. Archaeological evidence suggest Bronze Age man was living here as early as 850BC.
However, the castle you will undoubtedly have seen dates back to at least the 11th century, when Queen Margaret, recently widowed by the death of her husband, Malcolm III, stayed here. The chapel built in her memory is now the oldest remaining structure in the Edinburgh Castle complex.
Between 1296 and 1314, Edinburgh Castle was held by the English after being captured by Edward I. A brave surprise attack by Sir Thomas Randolph and his men recaptured the castle after they scaled the rock face.
The castle remained a royal residence until the 16th century, having a strong link with Mary Queen of Scots who lived there.
In 1573, sadly much of the early castle was destroyed in the Lang Siege when Sir William Kirkaldy of Grange began bombarding the town. The subsequent rebuilding led to the appearance of the castle we see today.
During the 1745 Jacobite Rising under “Bonnie Prince Charlie”, Edinburgh Castle saw its last battle, albeit much more sedate than previous uprisings. Following this, the castle was used to hold prisoners of war.
Since the 1830s, Edinburgh Castle has been put on public display. It is most famous for this today, opening up many of its rooms to displays. The public can get great views over Edinburgh from the castle, and also see the famous gun Mons Meg, which was returned to the castle from London in 1829. It dates from 15th century Flanders.
Wikipedia is a fantastic resource for a more detailed history of Edinburgh Castle.
The official website for Edinburgh Castle, with information on opening times and prices, is http://www.edinburghcastle.gov.uk/
