The town's site has long been of strategic significance. Around AD 75 a fort was built by the Romans during their conquest of Britain. An excavation of the site in 1963 showed that the fort was occupied by Roman forces until the middle of the 2nd century.
Tradition states that a monastery was built in the area by St Cenydd, but this claim lacks support. Nonetheless, the district was formerly named Senghenydd after him, and Cenydd's son, St Ffili, is said to have built a fort (Welsh: caer) in the area and thus gave the town its name. Another explanation is that it is named after the Anglo-Norman Marcher Lord, Philip de Braose.
Following the Norman invasion of Wales in the late 11th century, the area of Sengenhydd remained in Welsh hands. By the middle of the 12th century the area was under the control of the Welsh chieftain Ifor Bach (Ifor ap Meurig). His grandson Gruffydd ap Rhys was the final Welsh lord of Sengenhydd, falling to the English nobleman Gilbert de Clare, the Red Earl, in 1266. In 1267 Henry III was forced to recognise Llywelyn ap Gruffudd as Prince of Wales, and by September 1268 Llywelyn had secured northern Sengenhydd. Gilbert de Clare had already begun to take steps to consolidate his own territorial gains, beginning the construction of Caerphilly Castle on 11 April 1268. The castle would also act as a buffer against Llewelyn's own territorial ambitions and was attacked by the Prince of Wales' forces before construction was halted in 1270. Construction recommenced in 1271 and was continued under the Red Earl's son, Gilbert de Clare, 8th Earl of Gloucester. With only interior remodelling carried out to the castle by Hugh le Despenser in the 1320s, Caerphilly Castle remains a pure example of 13th century military architecture and is the largest castle in Wales, and the second largest in Britain (after Windsor).
The original town of Caerphilly grew up as a small De Clare raised settlement just south of the castle. In 1316 Llywelyn Bren, believed to be the son of Gruffyd ap Rhys and therefore great-grandson of Ifor Bach, led an insurrection, laying siege to the castle. The outer ward of the castle was breached but not the inner defences, with the town itself burned. The town was rebuilt but remained very small throughout the Middle Ages. The first evidence of its emerging importance was the construction of a Court House in the 14th century, the only pre-19th century building still remaining in the town.
At the beginning of the 15th century the castle was again attacked, this time by Owain Glyndŵr, who took control of the castle around 1403-05. Repairs to the castle continued until at least 1430, but just a century later the antiquary John Leland recorded that the castle was a ruin set in marshland, with a single tower being used as a prison. In the mid-16th century the 2nd Earl of Pembroke used the castle as a manorial court, but in 1583 the castle was leased to Thomas Lewis, who accelerated the castle's dilapidation by removing stonework to build his nearby manor, The Van. The Lewis family, who claimed descent from Ifor Bach, left the manor in the mid-18th century when they purchased St Fagans Castle, The Van falling into decay.
During the 1700s, Caerphilly began to grow into a market town, and during the 19th century, as the South Wales valleys underwent massive growth through industrialisation, so to the town's population grew. Caerphilly railway station was opened in 1871, and in 1899 the Rhymney Railway built their Caerphilly railway works maintenance facilities; however, the expansion of the population in the 19th century was more to do with the increasing market for coal.
Caerphilly is featured in the Sex Pistols documentary The Filth and the Fury. Protests and a prayer meeting were held outside the Castle Cinema on the evening of 14 December 1976, when the Pistols were playing a concert there. However, at this point in time, Caerphilly was one of the few councils that would allow the group to perform (Leeds and Manchester being the others). The castle of Caerphilly was used as a filming location for Merlin and the Doctor Who episodes The Rebel Flesh and The Almost People (2011).
Caerphilly hosted the National Eisteddfod in 1950.
Caerphilly is the birthplace of comedian Tommy Cooper, Newport County midfielder David Pipe and Arsenal midfielder Aaron Ramsey. It was also home to Cardiff City F. C. and Wales footballer Robert Earnshaw, following his family's move from Zambia.
The town has a rugby union club, Caerphilly RFC, who play in Division Three East of the Welsh National League.
The town has hosted a food fair, The Big Cheese, in and around Caerphilly Castle every summer since 1998. Visitor numbers reached 80,000 in 2012. The event includes a wide variety of cheese stalls as well as a funfair, fireworks and a cheese race around the castle.
It hosts a fundraising musical event called Megaday. In the Winter there is also the Festival of Light, which involves the procession of hundreds of lanterns through the centre of the town.
In 2012 Caerphilly County's only art gallery, Y Galeri, opened in St Fagan’s Street in the town centre. It was part of plans to build a wider Arts Centre with exhibitions, workshops and talks.
The Caerphilly Heart Disease Study (also known as the Caerphilly Prospective Study) is one of the world's longest running epidemiology studies. Since 1979, a representative sample of adult males born between 1918 and 1938, living in Caerphilly and the surrounding villages of Abertridwr, Bedwas, Machen, Senghenydd and Trethomas, have participated in the study. A wide range of health and lifestyle data have been collected throughout the study and have been the basis for over 400 publications in the medical press. A notable report was on the reductions in vascular disease, diabetes, cognitive impairment and dementia attributable to a healthy lifestyle.
The A469 trunk road runs through the town north to south, while the A468 skirts the northern boundary of the town.
Caerphilly has three railway stations: Caerphilly at the southern end of the town near the shopping area, Aber in the western part of the town and Energlyn & Churchill Park railway station in the far western part of the town. All on the Rhymney Line serving Cardiff.
The nearest airport is Cardiff which is just under 20 miles (32km) away.See also Category:People from Caerphilly
The pop-punk band Attack! Attack! were formed in Caerphilly.
Margaret Bevan, girl evangelist
Manon Carpenter, Mountain bike World Champion
Aaron Ramsey, Wales and Arsenal Midfielder.
Malcolm Uphill, professional motorcycle racer.
Tommy Cooper, Welsh comedian and magician, was born in Caerphilly. There is a statue commemorating him in the Twyn area.
Sian Evans, Singer-songwriter of the band Kosheen.
Donald Braithwaite, Former professional boxer, Bronze medalist at the 1958 British Empire and Commonwealth Games
Matt Johnson, Welsh TV presenter from Caerphilly.
Craig Roberts, Welsh actor and director from Maesycwmmer, Caerphilly.
Leona Vaughan, Welsh actress from Caerphilly.