Caerphilly Castle was built in the second half of the 13th century, as part of the Anglo-Norman expansion into South Wales. The Normans began to make incursions into Wales from the late 1060s onwards, pushing westwards from their bases in recently occupied England. Their advance was marked by the construction of castles and the creation of regional lordships. 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. The powerful de Clare family acquired the earldom in 1217 and continued to attempt to conquer the whole of the Glamorgan region.
In 1263, Gilbert de Clare, also known as "Red Gilbert" because of the colour of his hair, inherited the family lands. Opposing him in Glamorgan was the native Welsh prince Llywelyn ap Gruffudd. 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. 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. De Clare believed his lands and power were under threat and allied himself with Henry III against the rebel barons and Llywelyn.
The baronial revolt was crushed between 1266 and 1267, leaving de Clare free to advance north into Glamorgan from his main base in Cardiff. De Clare started to construct a castle at Caerphilly to control his new gains in 1268. The castle lay in a basin of the Rhymney Valley, alongside the Rhymney River and at the heart of network of paths and roads, adjacent to a former Roman fort. 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. The walls and internal buildings were built at speed, forming the main part of the castle. The architect of the castle and the precise cost of the construction are unknown, but modern estimates suggest that it could have cost as much as castles such as Conwy or Caernarfon, perhaps as much as £19,000, a huge sum for the period.
Llywelyn responded by intervening with his own forces but outright conflict was prevented by the diplomatic efforts of Henry III. De Clare continued building work and in 1270 Llywelyn responded by attacking and burning the site, probably destroying the temporary defences and stores. De Clare began work again the following year, raising tensions and prompting Henry to send two bishops, Roger de Meyland and Godfrey Giffard, to take control of the site and arbitrate a solution to the dispute.
The bishops took possession of the castle later in 1271 and promised Llywelyn that building work would temporarily cease and that negotiations would begin the following summer. In February of the next year, however, de Clare's men seized back the castle, threw out the bishops' soldiers, and de Clare – protesting his innocence in these events – began work once again. Neither Henry nor Llywelyn could readily intervene and de Clare was able to lay claim to the whole of Glamorgan. Work on the castle continued, with additional water defences, towers and gatehouses added.
Llywelyn's power declined over the next two decades. In 1276 Henry's son, Edward I, invaded Wales following a dispute with the prince, breaking his power in South Wales, and in 1282 Edward's second campaign resulted in Llwelyn's death and the collapse of independent Welsh rule. Further defences were added to the walls until work stopped around 1290. Local disputes remained. De Clare argued with Humphrey de Bohun, the earl of Hereford, in 1290 and the following year the case was brought before the king, resulting in the temporary royal seizure of Caerphilly.
In 1294 Madog ap Llywelyn rebelled against English rule, the first major insurrection since the 1282 campaign. The Welsh appear to have risen up over the introduction of taxation and Madog had considerable popular support. In Glamorgan, Morgan ap Maredudd led the local uprising; Morgan had been dispossessed by de Clare in 1270 and saw this as a chance to regain his lands. Morgan attacked Caerphilly, burning half of the town, but failed to take the castle. In the spring of 1295 Edward pressed home a counter-attack in North Wales, putting down the uprising and arresting Madog. De Clare attacked Morgan's forces and retook the region between April and May, resulting in Morgan's surrender. De Clare died at the end of 1295, leaving Caerphilly Castle in a good condition, linked to the small town of Caerphilly which had emerged to the south of it and a large deer park in the nearby Aber Valley.
Gilbert's son, also called Gilbert de Clare, inherited the castle, but he died fighting at the battle of Bannockburn in 1314 while still quite young. The family's lands were initially placed under the control of the Crown, but before any decision could be taken on the inheritance, a revolt broke out in Glamorgan. 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. The castle withstood the attack, but the town was destroyed and the rebellion spread. 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.
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. Hugh used his relationship with the king to expand his power across the region, taking over lands throughout South Wales. Hugh employed Master Thomas de la Bataile and William Hurley to expand the Great Hall at the castle, including richly carved windows and doors. In 1326, however, Edward's wife, Isabella of France, overthrew his government, forcing the king and Hugh to flee west. The pair stayed in Caerphilly Castle at the end of October and early November, before leaving to escape Isabella's approaching forces, abandoning the extensive stores and £14,000 held at the castle. William la Zouche besieged the castle with a force of 425 soldiers, cornering the constable, Sir John de Felton, Hugh's son – also called Hugh – and the garrison of 130 men inside. Caerphilly held out until March 1327, when the garrison surrendered on the condition that the younger Hugh was pardoned, his father having been already executed.
Tensions between the Welsh and the English persisted and spilled over in 1400 with the outbreak of the Glyndŵr Rising. It is uncertain what part the castle played in the conflict, but it seems to have survived intact. In 1416, the castle passed through Isabel le Despenser in marriage to her first husband Richard de Beauchamp, the earl of Worcester, and then to her second husband, Richard Beauchamp, the earl of Warwick. Isabel and her second husband invested heavily in the castle, conducting repairs and making it suitable for use as their main residence in the region. The castle passed to Richard Neville in 1449 and to Jasper Tudor, the earl of Pembroke, in 1486.
After 1486, the castle went into decline, eclipsed by the more fashionable residence of Cardiff Castle; once the sluice-gates fell into disrepair, the water defences probably drained away. 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. Henry Herbert, the earl of Pembroke used the castle for his manorial court. In 1583 the castle was leased to Thomas Lewis, who stripped it of much of its stone to extend his house, causing extensive damage.
In 1642 the English Civil War broke out between the Royalist supporters of Charles I and those of Parliament. South Wales was predominantly Royalist in sympathy, and during the conflict, a sconce, or small fort, was built overlooking Caerphilly Castle to the north-west, on the site of the old Roman fort. 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. It is also uncertain whether or not Caerphilly Castle was deliberately slighted by Parliament to prevent its future use as a fortification. Although several towers had collapsed by the 18th century, possibly as a result of such an operation, it is probable that this deterioration was actually the result of subsidence damage caused when the water defences retreated, as there is no evidence of deliberate destruction having been ordered.
The Marquesses of Bute acquired the castle in 1776. John Stuart, the first marquess, took steps to protect the ruins. 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. He had the site fully surveyed by the architect William Frame, and reroofed the great hall in the 1870s. The marquess began a process of buying back leasehold properties around the castle with the intent of clearing back the town houses that had been built up to the edge of the site.
The fourth marquess, John Crichton-Stuart, was an enthusiastic restorer and builder and commissioned a major restoration project between 1928 and 1939. The stonework was carefully repaired, with moulds made to recreate missing pieces. The Inner East Gatehouse was rebuilt, along with several of the other towers. 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.
By 1947, when John Crichton-Stuart, the fifth marquess, inherited the castle, the Bute family had divested itself of most of its land in South Wales. John sold off the family's remaining property interests and in 1950 he gave Caerphilly Castle to the state. The lakes were re-flooded and the final stages of the restoration work were completed in the 1950s and 1960s. In the 21st century the castle is managed by the Welsh heritage agency Cadw as a tourist attraction. In 2006, the castle saw 90,914 visitors. It is protected as a scheduled monument and as a grade I listed building.
Caerphilly Castle comprises a set of eastern defences, protected by the Outer East Moat and the North Lake, and fortifications on the Central Island and the Western Island, both protected by the South Lake. The site is around 30 acres (120,000 m2) in size, making it the second largest in Britain. It is constructed on a natural gravel bank in the local river basin, and the castle walls are built from Pennant sandstone. The castle's architecture is famous and historically significant. The castle introduced concentric castle defences to Britain, changing the future course of the country's military architecture, and also incorporated a huge gatehouse. 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".
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. Originally the gatehouse would have been reached over a sequence of two drawbridges, linked by an intervening tower, since destroyed. To the north side of the gatehouse was the North Dam, protected by three substantial towers, and which may have supported the castle's stables. Despite subsidence damage, the dam still holds back the North Lake. The South Dam was a massive structure, 152 metres (499 ft) long, ending in a huge buttressed wall. The remains of the castle mill – originally powered by water from the dam – survive. Four replica siege engines have been placed on display. The dam ended in Felton's Tower, a square fortification designed to protect the sluicegates regulating the water levels of the dam, and the South Gatehouse – also called Giffard's Tower – originally accessed via a drawbridge, which led into the town.
Caerphilly's water defences were almost certainly inspired by those at Kenilworth, where a similar set of artificial lakes and dams was created. Gilbert de Clare had fought at the siege of Kenilworth in 1266 and would have seen these at first hand. 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.
The central island held Caerphilly's inner defences, a roughly square design with a walled inner and middle ward, the inner ward protected by four turrets on each of the corners. The walls of the inner ward overlooked those of the middle ward, producing a concentric defence of two enclosed rings of walls; in the medieval period, the walls of the middle ward would have been much higher than today, forming a more substantial defence. Caerphilly was the first concentric castle in Britain, pre-dating Edward I's famous programme of concentric castles by a few years. The design influenced the design of Edward's later castles in North Wales, and historian Norman Pounds considers it "a turning point in the history of the castle in Britain". Probable subsidence has caused the south-east tower in the Inner Ward to lean outwards at an angle of 10 degrees.
Access to the central island occurred over a drawbridge, through a pair of gatehouses on the eastern side. Caerphilly Castle's Inner East Gatehouse, based on the gatehouse built at Tonbridge in the 1250s, reinforced a trend in gatehouse design across England and Wales. Sometimes termed a keep-gatehouse, the fortification had both exterior and interior defences, enabling it to be defended even if the perimeter of the castle was breached. Two huge towers flanked the gatehouse on either side of an entrance that was protected by portcullises and murder-holes. 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. Another pair of gatehouses protected the west side.
Inside the inner ward was the castle's Great Hall and accommodation. Caerphilly was built with fashionable, high-status accommodation, similar to that built around the same time in Chepstow Castle. 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. 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. To the east of the Great Hall was the castle chapel, positioned above the buttery and pantry. On the west side of the hall were the castle's private apartments, two solar blocks with luxurious fittings.
Beyond the central island was the Western Island, probably reached by drawbridges. The island is called Y Weringaer or Caer y Werin in Welsh, meaning "the people's fort", and may have been used by the town of Caerphilly for protection during conflicts. 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.
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. On that occasion, producers used the residential quarters of the East Gatehouse, Constable's Hall and Broase Gallery for the filming of a dungeon in the fictional Broadfell Prison.