The castle was commissioned either by William the Conqueror or by Robert Fitzhamon, and formed the heart of the medieval town of Cardiff and the Marcher Lord territory of Glamorgan.
Cardiff Castle was repeatedly involved in the conflicts between the Anglo-Normans and the Welsh, being attacked several times in the 12th century, and stormed in 1404 during the revolt of Owain Glyndŵr.
The Herbert family took over the property in 1550, remodelling parts of the main lodgings and carrying out construction work in the outer bailey, then occupied by Cardiff's Shire Hall and other buildings.
When fighting broke out again in 1648, a Royalist army attacked Cardiff in a bid to regain the castle, leading to the Battle of St Fagans just outside the city.
The 1st Marquess of Bute employed Capability Brown and Henry Holland to renovate the main lodgings, turning it into a Georgian mansion, and to landscape the castle grounds, demolishing many of the older medieval buildings and walls.
[9] A fourth fort was built in the middle of the 3rd century in order to combat the pirate threat along the coast, and forms the basis of the Roman remains seen on the castle site.
[19] The site was close to the sea and could be easily supplied by ship, was well protected by the Rivers Taff and Rhymney and also controlled the old Roman road running along the coast.
[27] Anglo-Saxon peasants settled the region around Cardiff, bringing with them English customs, although Welsh lords continued to rule the more remote districts almost independently until the 14th century.
[33] Around the middle of the century, possibly under Robert of Gloucester, a 77-foot (23 m) wide, 30-foot (9 m) high shell keep was constructed on top of the motte, along with a stone wall around the south and west sides of the inner bailey.
This was contrary to legal custom in England, and was done in order that Henry could then marry her to his youngest son Prince John and thus provide him with extensive lands.
[40] Gilbert's son, Richard de Clare, 6th Earl of Gloucester, carried out building work at the castle in the late 13th century, constructing the Black Tower that forms part of the southern gateway seen today.
[52] He also constructed a substantial new domestic range in the south-west of the site between 1425 and 1439, with a central octagonal tower 75-foot (23 m) high, sporting defensive machicolations, and featuring four smaller polygonal turrets facing the inner bailey.
[53] The range was built of Lias ashlar stone with limestone used for some of the details, set upon the spur bases characteristic of South Wales and incorporated parts of the older 4th and 13th century walls.
[56] Richard also rebuilt the town's wider defences, including a new stone bridge over the River Taff guarded by the West Gate, finishing the work by 1451.
[63] The Shire Hall had been built in the outer bailey, forming part of a walled complex of buildings that included the lodgings for the traditional twelve holders of castle-guard lands.
[71] In early 1645 Mr Carne, the High Sheriff, rebelled against Parliament, taking Cardiff town but initially failing to seize the castle.
[72] With the Royalist military position across the country worsening, King Charles himself came to Cardiff Castle that July to meet with local Welsh leaders.
[76] Parliamentary forces in Brecon under the command of Colonel Thomas Horton moved quickly to reinforce the castle, although with only 3,000 men they were content to wait until a larger army under Oliver Cromwell could arrive from Gloucester.
[79] Herbert's daughter, Charlotte Jane Windsor, married, in November 1766, John, Lord Mount Stuart, who rose to become the Marquess of Bute in 1794, beginning a family line that would control the castle for the next century.
[83] Considerable work was carried out on the main lodgings, demolishing the Herbert additions, building two new wings and removing many of the older features to produce a more contemporary, 18th-century appearance.
[85] Further work was planned on the property, including a reported proposal to roof the keep in copper, insert new windows and turn it into an assembly room for dances, but these projects were cut short by the death of Bute's son in 1794.
The two shared a passion in medieval Gothic Revivalism and this, combined with Bute's huge financial resources, enabled Burges to rebuild the property on a grand scale.
The tower contains 7 ornate statues standing 9-foot (2.7 m) tall and carved in stone representing Mercury, Luna (moon), Mars, Jupiter, Saturn, Venus and Sol (sun).
[102] In his A History of the Gothic Revival, written as the tower was being built, Charles Locke Eastlake wrote of Burges's "peculiar talents (and) luxuriant fancy.
"[103] The Summer Smoking Room rested at the top of the structure and was two storeys high with an internal balcony that, through an unbroken band of windows, gave views of the Cardiff Docks, the Bristol Channel, and the Glamorgan countryside.
The Octagon Tower followed, including an oratory, built on the spot where Bute's father died, and the Chaucer Room, the roof of which is considered by historian Mark Girouard to be a "superb example of Burges's genius".
The historian Megan Aldrich considers them amongst "the most magnificent that the gothic revival ever achieved", J. Mordaunt Crook has described them as "three dimensional passports to fairy kingdoms and realms of gold", and John Newman praises them as "most successful of all the fantasy castles of the nineteenth century.
[121] During World War II, extensive tunnels within the medieval walls were used as air-raid shelters, with eight different sections, able to hold up to 1,800 people in total,[122] and the castle was also used to tether barrage balloons above the city.
[128] A new interpretation centre, which opened in 2008, was built alongside the South Gate at a cost of £6 million,[129] and the castle also contains "Firing Line", the joint regimental museum of the 1st The Queen's Dragoon Guards and the Royal Welsh.
The castle has seen various musical performances, including by Westlife, Tom Jones, A-HA, Green Day and the Stereophonics, with a capacity to accommodate over 10,000 people.