Gilbert began work on the castle in 1268 following his occupation of the north of Glamorgan, with the majority of the construction occurring over the next three years at a considerable cost.
The project was opposed by Gilbert's Welsh rival Llywelyn ap Gruffudd, leading to the site being burnt in 1270 and taken over by royal officials in 1271.
The Normans began to make incursions into Wales from the late 1060s onwards, pushing westwards from their bases in recently occupied England.
[6] The task of subduing the region of Glamorgan was given to the earls of Gloucester in 1093; efforts continued throughout the 12th and early 13th centuries, accompanied by extensive fighting between the Anglo-Norman lords and local Welsh rulers.
[8] Llywelyn had taken advantage of the chaos of the civil war in England between Henry III and rebel barons during the 1260s to expand his power across the region.
[10] In 1265 Llywelyn allied himself with the baronial faction in England in exchange for being granted authority over the local Welsh magnates across all the territories in the region, including Glamorgan.
[12] The baronial revolt was crushed between 1266 and 1267, leaving de Clare free to advance north into Glamorgan from his main base in Cardiff.
[14] Work began at a huge pace, with ditches cut to form the basic shape of the castle, temporary wooden palisades erected and extensive water defences created by damming a local stream.
[17] De Clare continued building work and in 1270 Llywelyn responded by attacking and burning the site, probably destroying the temporary defences and stores.
[19] Anger over the actions of the royal administrators caused Llywelyn Bren to rise up in January 1316, attacking Caerphilly Castle with a large force of men.
[25] A royal army was despatched to deal with the situation, defeating Bren in a battle at Caerphilly Mountain and breaking the Welsh siege of the castle.
[25] In 1317 Edward II settled the inheritance of Glamorgan and Caerphilly Castle on Eleanor de Clare, who had married the royal favourite, Hugh le Despenser.
[27] Hugh employed Master Thomas de la Bataile and William Hurley to expand the Great Hall at the castle in 1325–1326, including richly carved windows and doors.
[39] Antiquarian John Leland visited Caerphilly Castle around 1539, and described it as having "waulles of a wonderful thiknes", but beyond a tower used to hold prisoners it was in ruins and surrounded by marshland.
[41] It is uncertain if this was built by Royalist forces or by the Parliamentary army that occupied the area during the final months of the war in March 1646, but the fort's guns would have dominated the interior of the castle.
[31] His great-grandson John Crichton-Stuart, the third marquess, was immensely rich as the result of the family's holdings in the South Wales coalfields and was passionately interested in the medieval period.
[48] The marquess carried out landscaping work, with the intent of eventually re-flooding the lakes, and thanks to several decades of purchases was finally able to demolish the local houses encroaching on the view of the castle.
[58] The castle also featured a sophisticated network of moats and dams, considered by historian Allen Brown to be "the most elaborate water defences in all Britain".
[3] The eastern defences were reached via the Outer Main Gatehouse, which featured circular towers resting on spurred, pyramidic bases, a design particular to South Wales castles.
[65] Caerphilly's water defences provided particular protection against mining, which could otherwise undermine castle walls during the period, and are considered the most advanced of their kind in Britain.
[74] The substantial size of the gatehouse allowed it to be used for accommodation as well as defence and it was comfortably equipped on a grand scale, probably for the use of the castle constable and his family.
[77] In the medieval period the Great Hall would have been subdivided with wooden screens, colourful decorations, with rich, detailed carving and warmed by a large, central fireplace.
[78] Some carved medieval corbels in the shape of male and female heads survive in the hall today, possibly depicting the royal court in the 1320s, including Edward II, Isabella of France, Hugh Despenser and Eleanor de Clare.
[82] On the north-west side of the Western Island was the site of the former Roman fort, enclosing around 3 acres (1.2 ha), and the remains of the 17th-century civil-war fortification built on the same location.
[76] The long-running British television show Doctor Who chose Caerphilly Castle as a filming location for several episodes, including "The End of Time" in 2009, "The Vampires in Venice" in 2010, two parter "The Rebel Flesh" and "The Almost People" in 2011; “Robot of Sherwood" in 2014 and “Heaven Sent” in 2015.
For "The End of Time", producers used the residential quarters of the East Gatehouse, Constable's Hall and Braose Gallery for the filming of a dungeon in the fictional Broadfell Prison.