Castle building in Iberia left a lasting impression upon the landscape, language, settlement patterns, and laws of the peninsula, which is one of the most heavily castellated parts of western Europe. Estimates of numbers of Iberian castles, walled cities, and fortified places vary between 2,000 and 10,000, depending upon how each structure is defined. The numerous fortifications result from the ongoing warfare between Christians and Muslims during the reconquest of the Iberian Peninsula (711-1492) and the fourteenth- and fifteenth-century civil wars among Christians. Decades of warfare along static military frontiers from the Roman period until the late Middle Ages necessitated frequent refortification of strategic sites. Castles in Spain often consist of layers of construction; Visigothic fortifications incorporated Roman foundations, which subsequent builders enhanced and augmented. Towns and cities followed the same process, repairing Roman walls or building new ones as the situation required.
The Muslim invasion of 711 introduced the Eastern style of military architecture into the peninsula. From the eighth century to the middle of the twelfth century, the Muslims built fortifications called alcazabas, designed to hold garrisons or to protect the rural population. The builders adapted the shape of the enceinte to the terrain, locating small gates near the corners. The walls were constructed from tapia (a mixture of cement and pebbles or stones), which was poured into forms where it hardened. This method of construction determined the rectangular shape of the towers. The crenelations had pointed merlons (the structures separating the embrasures, or openings, atop a parapet). Lesser buildings within the enceinte housed workshops, barracks, and kitchens. Rural castles had a central redoubt (Arab. salüqiya, Romance celoquia), which was the residence of the castellan (Arab. qa'id, Romance alcaid). The walled-in space was called the baqqar or albacar. The villages dependent on the castle were the qura (Arabic) or the alqueria (Romance). From the middle of the twelfth century until the fall of Seville in 1248, there was general adoption of tapia work, towers with large salients, and octagonal and dodecagonal plans. The stone-built alcazar (a fortified palace) developed in the thirteenth and fourteenth centuries from the alcazaba. The word alcazar entered the Spanish language to mean an urban fortification. Torres albarranas were massive keeps located outside the enceinte and connected by a walkway. From 1248 until the conquest of Granada in 1492, the complex construction of the Alhambra, with its large towers, became the prototype of Iberian Muslim castles.

The Alcazar in Segovia (Corel)
Christian castles of the ninth and tenth centuries (Lat. castrum and castellum, pl. castri and castelli) probably were surrounded by wooden palisades. The torre del homenaje (main tower) dominated tenth-century Christian castles: it was built within the enceinte, and Christians added torres del homenaje to captured Muslim alcabazas. Building materials consisted of brick and stone rubble, and the layout was adapted to the topography of the ground. Stone-built castles with walls and keep appeared by the eleventh century, and wealthy lords walled entire towns as well. Twelfth-century castles bore similarities to French styles. By the late thirteenth to the end of the fourteenth century, the military orders built castles with extended walls to protect important centers. Castillos roqueros were smaller, irregularly planned castles constructed on high and inaccessible locations and making use of natural features. By the fourteenth and fifteenth centuries, Christians built symmetrically planned stone castles on the plains that had round towers at the corners and a square or rectangular torre del homenaje. In contrast to other parts of Europe, Iberian castle builders did not develop fortified gates and gatehouses.
Nobles, high-ranking churchmen, and townspeople also built and maintained fortifications during the period of the reconquest. In the twelfth century, Castilian kings granted frontier castles to noble tenants. These castles remained military structures in the service of the Crown and did not become hereditary fiefs. Churchmen, in their capacity as temporal lords, also built and maintained castles. The military orders dominated castle construction from the late twelfth until the fourteenth century, particularly along the frontier. Ecclesiastical buildings also functioned as fortified places; the cathedral located within the walled city of Avila resembles a castle. Other churches employed a very solid interpretation of the Romanesque style, and either augmented the town walls or served as a place of refuge for a rural population. Monasteries were encircled with walls, and some, such as Poblet, were fortified. The towns and cities levied tolls to maintain their walls, gates, and watch- towers, although they also received royal subsidies in times of great danger.
Though most Iberian castles were built as military installations, residential castles began to evolve in the thirteenth century. Lords wealthy from the reconquest renovated older castles, well away from the frontier, according to French style. Urban castles also became residences. The fortified nobiliary residences were put to military use during civil wars in the fourteenth and fifteenth centuries, but many were demolished during the reigns of Ferdinand II of Aragon and Isabella I of Castile. By the fifteenth and sixteenth centuries, the rulers of Spain began construction of castle-palaces, similar in scope, if not in style, to the Alhambra.
The placement of Iberian castles in the landscape reflected both settlement patterns and military frontiers. The Christians built systems of castles around strategic cities as a defensive shield: examples are the lines of castles built along the Tordera River to defend Barcelona from the north, and the castles along the Tagus River, which shielded Toledo from the south. In this system, part of the barrier might fall, but the main city remained secure. Watchtow- ers built on high ground to observe enemy movement and isolated tower houses formed part of the system of defense. Muslim castles, like Christian ones, functioned as part of a system for collecting peasant taxes and maintaining organized systems of land ownership. Archaeological excavations have established the castle and the village as the basic unit of rural settlement (Arab. hisn/qirya). The size of the castle was determined by the number of the population who took refuge in it, rather than by the strategic importance of the area, as in Christian fortifications.
In addition to the archaeological remains, a substantial number of legal and notarial documents record the transfer, sale, and acquisition of castles. Christian settlement charters bestowed castles with their dependent villages (Rom. alqueria) on noble tenants. Castles feature in royal dowries and peace treaties. Laws regarding royal castles, their maintenance, provisioning, defense, and transfer form a significant part of codes such as the Usatges of Barcelona, Partida II of the Siete Partidas of Alfonso X of Castile, and the Costum d’Espanya. Finally, most of the major Christian chronicles, such as the Chronica Adefonsi Imperatoris and the Vita of James I of Aragon, detail sieges and raids of castles.