Caerphilly castle was not built by Edward I in his crack-down on the Welsh lords, unlike many other Welsh castles, but by Gilbert 'the Red' de Clare, a powerful, redheaded nobleman of Norman descent as a response to a dispute between him and a nobleman of Welsh origin, Llywelyn who was later a supporter of Simon de Montfort.
At first the dispute was mediated by Henry III (1216-1272), remembered by some as pious but feeble, who sent a Bishop to take temporary control of the castle until matters were settled. Through a fairly straightforward deceit, Gilbert regained control of the castle. Henry, perhaps typically, did little or nothing about it.
So things remained until the reign of Edward I (1272-1307). When Llywelyn failed on five occasions to provide services demanded of him by the King, he was stripped of his lordship and his lands were invaded by Edward. This removed much of the requirement for the castle, and from then on it was principally used as a base of operations for the de Clares and later the Despensers. Towards the end of the 14th century, the family moved to a more comfortable location and much of the castle was abandoned. Some maintenance was done by its subsequent owners, Richard Beauchamp (d. 1439), Richard Neville (d. 1471) and Jasper Tudor (d. 1495), probably because of its strategic usefulness, but this petered out at the end of the 15th century.
The castle gradually fell into disrepair though some maintenance was done on parts of it, notably the Eastern gate house which was used as a prison. Despite being mostly untouched by the Civil War of 1642-1648, damage inflicted by the parliamentary army in 1648 led to one of the most notable features of the castle, its leaning south-east tower. The castle's condition worsened until the later part of the 18th century when the first Marquess of Bute began preservation work. Three generations of Marquesses recorded the details of the castle, cleared structures built against its walls as leases ended and eventually undertook painstaking analysis and restoration of the fallen masonry. Finally it was handed over to the government in 1950 and restoration and preservation is continued to this day by Cadw (Welsh Historic Monuments).
Several replica siege engines are on display in the castle.