Signboards around Caerphilly Castle proudly proclaim that it is "Wales' largest castle" and it is indeed quite vast in its extent, though it probably depends how you measure these things as both Pembroke and Caernarfon 'feel' bigger in their true castle buildings as opposed to the area enclosed by their curtain walls (which in Caerphilly's case are particularly extensive).
The original castle was build in four phases:
de Clare phase 1: 1268 - mid 1270s
de Clare phase 2: 1278 - c.1285
de Clare phase 3: c.1285 - 1300
Despenser: 1317 - 1326
Then a major (and contentious) restoration was carried out by the Marquess of Bute between 1928 and 1939.
Many great castles were built in Wales during the reign of Edward I (1272-1307) and whilst they were certainly not popular with the locals at the time, they are now making the most of their legacy!
Caerphilly was begun by the extremely wealthy Marcher lord of Glamorgan, Gilbert de Clare (1243-1295) in 1268 as a defensive English stronghold against the uprisings of the Welsh, particularly Llywelyn ap Gruffudd. With Edward's defeat of the Welsh prince in 1278, de Clare commenced making the castle more of a home than simply a fortification with the addition of comfortable rooms along with a number of the towers and gatehouses.
In 1317 during the reign of the ineffectual (and ultimately doomed) Edward II, the lordship of Glamorgan passed by marriage to the king's 'favourite' Hugh Despenser the younger. His greatest modification to the castle being the rebuilding of the Great Hall to make it a suitable place to entertain the king.
But the castle was soon to see the end of its 'glory days'; by the mid C14th it fell out of favour as a residence for the lords of Glamorgan and it gradually declined until in 1590 the then owner allowed one Thomas Lewis to remove and use as much stone from it as he pleased in order to build his own nearby mansion of Y Fan.
Half a century later Cromwell then slighted it with a huge gunpowder explosion which I believe caused the South-East tower to lean to the dramatic extent it does today (considerably more than the famous campanile in Pisa does) - creating perhaps the castle's most 'iconic' feature.
See other images of Caerphilly Castle