Madrid is the capital and most populous city of Spain. It had a population of over 3.4 million in the city proper in 2025, and a metropolitan area population of approximately 6.8 million. Madrid is the second-largest city in the European Union (EU), after Berlin, and its metropolitan area is the second-largest in the EU, after Paris. The municipality covers an area of 605.77 square kilometres (233.89 sq mi). Madrid lies on the River Manzanares in the central part of the Iberian Peninsula at about 660 metres (2,170 ft) above mean sea level. The capital city of both Spain and the surrounding autonomous community of Madrid, it is the political, economic and cultural centre of the country.
The primitive core of Madrid, a walled military outpost, dates back to the late 9th century, under the Emirate of Córdoba. Conquered by Christians in 1083 or 1085, it consolidated in the Late Middle Ages as a sizeable town of the Crown of Castile. The development of Madrid as an administrative centre was fostered after 1561, as it became the permanent seat of the court of the Hispanic Monarchy. The following centuries were characterised by the reinforcement of Madrid's status within the framework of a centralised form of state-building.
The Madrid urban agglomeration has the second-largest GDP in the European Union. Madrid is ranked as an alpha world city by the Globalization and World Cities Research Network. The metropolitan area hosts major Spanish companies such as Telefónica, Iberia, BBVA and FCC. It concentrates the bulk of banking operations in Spain and it is the Spanish-speaking city generating the largest number of webpages. Madrid houses the headquarters of UN Tourism, the Ibero-American General Secretariat (SEGIB), the Organization of Ibero-American States (OEI), and the Public Interest Oversight Board (PIOB). Pursuant to the standardising role of the Royal Spanish Academy, Madrid is a centre for Spanish linguistic prescriptivism. Madrid organises fairs such as FITUR, ARCO, SIMO TCI and the Madrid Fashion Week. Madrid is home to football clubs Real Madrid and Atlético Madrid.

Madrid is one of Spain's leading destinations for international tourism. In 2023, it ranked second among Spanish tourist destinations with 5,757,815 international visitors. Madrid's main international source markets include the United States, Italy, France, the United Kingdom and Mexico. Its landmarks include the Plaza Mayor; the Royal Palace of Madrid; the Royal Theatre with its restored 1850 Opera House; the Buen Retiro Park, founded in 1631; the 19th-century National Library building containing some of Spain's historical archives; many national museums; and the UNESCO World heritage "Golden Triangle of Art", located along the Paseo del Prado and comprising three art museums: the Prado Museum; the Reina Sofía Museum, a museum of modern art; and the Thyssen-Bornemisza Museum, which complements the holdings of the other two museums. The mayor is José Luis Martínez-Almeida from the People's Party.
Etymology
The origin of the name is unknown. There are various theories regarding the origin of the toponym "Madrid", all of them with problems when it comes to fully explaining the phonetic evolution of the toponym. The Latin theory (Madrid < Matrice < Matrix) has gained support in the past decades:
A Celtic origin (Madrid < *Magetoritum; with the root "-ritu" meaning "ford").

From the Arabic maǧrà / majrā (meaning "water stream") or Arabic: مجريط, romanized: majrīṭ, lit. '"spring", "fountain"'.
A Mozarabic variant of the Latin matrix, matricis (also meaning "water stream").
Nicknames for Madrid include the plural Los Madriles and La Villa y Corte (lit. 'the town and court').

History
The site of modern-day Madrid has been occupied since prehistoric times. There are archaeological remains of the Celtic Carpetani settlement, Roman villas, a Visigoth basilica near the church of Santa María de la Almudena and three Visigoth necropolises near Casa de Campo, Tetuán and Vicálvaro.
Middle Ages
The first historical document about the existence of an established settlement in Madrid dates from the Muslim age. In the second half of the 9th century, Umayyad Emir Muhammad I built a fortress on a headland near the river Manzanares as one of the many fortresses he ordered built on the border between Al-Andalus and the kingdoms of León and Castile, with the objective of protecting Toledo from Christian attacks from the North and as a starting point for Muslim offensives. After the disintegration of the Caliphate of Córdoba in the early 11th century, Madrid was integrated in the Taifa of Toledo.
In the context of the wider campaign for the conquest of the taifa of Toledo initiated in 1079, Madrid was seized in 1083 by Alfonso VI of León and Castile, who sought to use the town as an offensive outpost against the city of Toledo, in turn conquered in 1085. Following the conquest, Christians occupied the centre of the city, while Muslims and Jews were displaced to the suburbs. Madrid, located near Alcalá (under Muslim control until 1118), remained a borderland for a while, suffering a number of razzias during the Almoravid period, and its walls were destroyed in 1110.

Madrid was confirmed as villa de realengo (linked to the Crown) in 1123, during the reign of Alfonso VII. The 1123 Charter of Otorgamiento established the first explicit limits between Madrid and Segovia, namely the Puerto de El Berrueco and the Puerto de Lozoya. Beginning in 1188, Madrid had the right to be a city with representation in the courts of Castile. In 1202, Alfonso VIII gave Madrid its first charter to regulate the municipal council, which was expanded in 1222 by Ferdinand III. The government system of the town was changed to a regimiento of 12 regidores by Alfonso XI in January 1346.
Starting in the mid-13th century and up to the late 14th century, the concejo of Madrid vied for the control of the Real de Manzanares territory against the concejo of Segovia, a powerful town north of the Sierra de Guadarrama mountain range, characterised by its repopulating prowess and its animal husbandry-based economy, in contrast to the agricultural and less repopulated town of Madrid. After the decline of Sepúlveda, another concejo north of the mountain range, Segovia became a major actor south of the Guadarrama mountains, expanding across the Lozoya and Manzanares rivers to the north of Madrid and along the Guadarrama river course to its west.
In 1309, the Courts of Castile convened at Madrid for the first time under Ferdinand IV, and later in 1329, 1339, 1391, 1393, 1419 and twice in 1435.
Early Modern Era
During the revolt of the Comuneros, led by Juan Lopez de Padilla, Madrid joined the revolt against Charles, Holy Roman Emperor. After defeat at the Battle of Villalar, Madrid was besieged and occupied by the imperial troops. The city was however granted the titles of Coronada (Crowned) and Imperial.
The number of urban inhabitants grew from 4,060 in 1530 to 37,500 in 1594. The poor population of the court was composed of ex-soldiers, foreigners, and rogues, dissatisfied with the lack of food and high prices. In June 1561 Phillip II set his court in Madrid, installing it in the old alcázar. Thanks to this, Madrid became the political centre of the monarchy, being the capital of Spain except for a short period between 1601 and 1606, in which the Court was relocated to Valladolid, and the Madrid population temporarily plummeted. Being the capital was decisive for the evolution of the city and influenced its fate. During the rest of the reign of Philip II, the population boomed, going up from about 18,000 in 1561 to 80,000 in 1598.
In the early 17th century, although Madrid recovered from the loss of its capital status, with the return of diplomats, lords and affluent people, as well as an entourage of noted writers and artists together with them, extreme poverty remained rampant. The century also was a time of heyday for theatre, represented in the so-called corrales de comedias.
Madrid changed hands several times during the War of the Spanish Succession: from the Bourbon control it passed to the allied "Austracist" army with Portuguese and English presence that entered the city in late June 1706, only to be retaken by the Bourbon army on 4 August 1706. The Habsburg army led by the Archduke Charles entered the city for a second time in September 1710, leaving the city less than three months after. Philip V entered the capital on 3 December 1710.
Seeking to take advantage of Madrid's location at the geographic centre of Spain, the 18th century saw a sustained effort to create a radial system of communications and transports for the country through public investments.
Philip V built the Royal Palace, the Royal Tapestry Factory and the main Royal Academies. The reign of Charles III, who came to be known as "the best mayor of Madrid", saw an effort to turn the city into a true capital, with the construction of sewers, street lighting, cemeteries outside the city and a number of monuments and cultural institutions. The reforms enacted by his Sicilian minister were however opposed in 1766 by the populace in the so-called Esquilache Riots, a revolt demanding to repeal a clothing decree banning the use of traditional hats and long cloaks aiming to curb crime in the city.
In the context of the Peninsular War, the situation in French-occupied Madrid after March 1808 was becoming more and more tense. On 2 May, a crowd began to gather near the Royal Palace protesting against the French attempt to evict the remaining members of the Bourbon royal family to Bayonne, prompting up an uprising against the French Imperial troops that lasted hours and spread throughout the city, including a famous last stand at the Monteleón barracks. Subsequent repression was brutal, with many insurgent Spaniards being summarily executed. The uprising led to a declaration of war calling all the Spaniards to fight against the French invaders.
Capital of the Liberal State
Madrid was invaded on 24 May 1823 by a French army—the so-called Hundred Thousand Sons of Saint Louis—called to intervene to restore the absolutism of Ferdinand that the latter had been deprived from during the 1820–1823 trienio liberal. Unlike other European capitals, during the first half of the 19th century the only noticeable bourgeois elements in Madrid (that experienced a delay in its industrial development up to that point) were merchants. The University of Alcalá de Henares was relocated to Madrid in 1836, becoming the Central University.
Madrid's economy modernised during the second half of the 19th century, consolidating its status as a service and financial centre. New industries were mostly focused in book publishing, construction and low-tech sectors. The introduction of railway transport greatly helped Madrid's economic prowess, and led to changes in consumption patterns, such as the substitution of salted fish for fresh fish from the Spanish coasts, and further strengthening Madrid's role as a logistics node in Spain's distribution network. Electric lighting in the streets was introduced in the 1890s.
During the first third of the 20th century the population nearly doubled, reaching more than 850,000 inhabitants. New suburbs such as Las Ventas, Tetuán and El Carmen became the homes of the influx of workers, while Ensanche became a middle-class neighbourhood of Madrid.
Second Republic and Civil War
The Spanish Constitution of 1931 was the first to legislate the location of the country's capital, setting it explicitly in Madrid. During the 1930s, Madrid enjoyed "great vitality"; it was demographically young, becoming urbanised and the centre of new political movements. During this time, major construction projects were undertaken, including the northern extension of the Paseo de la Castellana, one of Madrid's major thoroughfares. The tertiary sector, including banking, insurance and telephone services, grew greatly. Illiteracy rates were down to below 20%, and the city's cultural life grew notably during the so-called Silver Age of Spanish Culture; the sales of newspapers also increased.
The proclamation of the Republic created a severe housing shortage. Slums and squalor grew due to high population growth and the influx of the poor to the city. Construction of affordable housing failed to keep pace and increased political instability discouraged economic investment in housing in the years immediately prior to the Civil War. Anti-clericalism and Catholicism lived side by side in Madrid; the burning of convents initiated after riots in the city in May 1931 worsened the political environment. However, the 1934 insurrection largely failed in the city.
Madrid was one of the most heavily affected cities in the Spanish Civil War (1936–1939). It was a stronghold of the Republican faction from July 1936 and became an international symbol of anti-fascist struggle during the conflict. The city suffered aerial bombing, and in November 1936, its western suburbs were the scene of an all-out battle. The city fell to the Francoists in March 1939.
Francoist dictatorship
A staple of post-war Madrid (Madrid de la posguerra) was the widespread use of ration coupons. Meat and fish consumption was scarce, resulting in high mortality due to malnutrition. Due to Madrid's history as a left-wing stronghold, the right-wing victors considered moving the capital elsewhere (most notably to Seville), but such plans were never implemented. The Franco regime instead emphasised the city's history as the capital of formerly imperial Spain.
The intense demographic growth experienced by Madrid via mass immigration from the rural areas of Spain led to the construction of abundant housing in the peripheral areas of Madrid to absorb the new population, initially comprising substandard housing. This increased wealth polarisation in Madrid, with as many as 50,000 shacks scattered around Madrid by 1956. A transitional planning intended to temporarily replace the shanty towns were the poblados de absorción, introduced since the mid-1950s in locations such as Canillas, San Fermín, Caño Roto, Villaverde, Pan Bendito, Zofío and Fuencarral, aiming to work as a sort of "high-end" shacks (with the destinataries participating in the construction of their own housing) but under the aegis of a wider coordinated urban planning.
Madrid grew through the annexation of neighbouring municipalities, achieving the present extent of 607 km2 (234.36 sq mi). The south of Madrid became heavily industrialised, and there was significant immigration from rural areas of Spain. Madrid's newly built north-western districts became the home of a newly enriched middle class that appeared as result of the 1960s Spanish economic boom, while the south-eastern periphery became a large working-class area, which formed the base for active cultural and political movements.
Recent history
After the fall of the Francoist regime, the new 1978 constitution confirmed Madrid as the capital of Spain. The 1979 municipal election brought Madrid's first democratically elected mayor since the Second Republic to power.
Madrid was the scene of some of the most important events of the time, such as the mass demonstrations of support for democracy after the failed coup, 23-F, on 23 February 1981. The first democratic mayors belonged to the centre-left PSOE (Enrique Tierno Galván, Juan Barranco Gallardo). Since the late 1970s and through the 1980s Madrid became the centre of the cultural movement known as la Movida. Conversely, just like in the rest of the country, a heroin crisis took a toll in the poor neighbourhoods of Madrid in the 1980s.
Benefiting from increasing prosperity in the 1980s and 1990s, the capital city of Spain consolidated its position as an important economic, cultural, industrial, educational, and technological centre on the European continent. During the mandate as Mayor of José María Álvarez del Manzano construction of traffic tunnels below the city proliferated. The following administrations, also conservative, led by Alberto Ruiz-Gallardón and Ana Botella launched three unsuccessful bids for the 2012, 2016 and 2020 Summer Olympics. In 2005, Madrid was the leading European destination for migrants from developing countries, as well as the largest employer of non-European workforce in Spain.
In the early years of the 21st century, Madrid experienced the increase of income inequality and socio-economic segregation. Madrid was a centre of the anti-austerity protests that erupted in Spain in 2011. As consequence of the spillover of the 2008 financial and mortgage crisis, Madrid has been affected by the increasing number of second-hand homes held by banks and house evictions. The mandate of left-wing Mayor Manuela Carmena (2015–2019) delivered the renaturalization of the course of the Manzanares across the city.
Since the late 2010s, the challenges the city faces include the increasingly unaffordable rental prices (often in parallel with the gentrification and the spike of tourist apartments in the city centre) and the profusion of betting shops in working-class areas, leading to an "epidemic" of gambling among young people.
Geography
Madrid lies in the centre of the Iberian peninsula on the southern Meseta Central, 60 kilometres south of the Guadarrama mountain range and straddling the Jarama and Manzanares river sub-drainage basins, in the wider Tagus River catchment area. With an average altitude of 650 metres (2,130 ft), Madrid is the second-highest capital of Europe, after Andorra la Vella. The difference in altitude within the city proper ranges from the 700 m (2,297 ft) around Plaza de Castilla in the north of city to the 570 m (1,870 ft) around La China wastewater treatment plant on the Manzanares' riverbanks, near the latter's confluence with the Fuente Castellana thalweg in the south of the city.
The Monte de El Pardo, a protected forested area covering over a quarter of the municipality, reaches its top altitude (843 m (2,766 ft)) on its perimeter, in the slopes surrounding El Pardo reservoir located at the north-western end of the municipality, in the Fuencarral-El Pardo district.
The oldest urban core is located on the hills next to the left bank of the Manzanares River. Madrid grew to the east, reaching the Fuente Castellana Creek, now the Paseo de la Castellana, and further east reaching the Abroñigal Creek, now the M-30. Madrid also grew through the annexation of neighbouring urban settlements, including those to the South West on the right bank of the Manzanares.
Parks and forests
Madrid has the second highest number of aligned trees in the world, with 248,000 units, only exceeded by Tokyo. Madrid's citizens have access to a green area within a 15-minute walk. Since 1997, green areas have increased by 16%. At present, 8.2% of Madrid's grounds are green areas, meaning that there are 16 square metres (172 sq ft) of green area per inhabitant, far exceeding the ten-square-metre (110 sq ft) per inhabitant recommended by the World Health Organization.
A great bulk of the most important parks in Madrid are related to areas originally belonging to the royal assets (including El Pardo, Soto de Viñuelas, Casa de Campo, El Buen Retiro, la Florida and the Príncipe Pío hill, and the Queen's Casino). The other main source for the "green" areas are the bienes de propios owned by the municipality (including the Dehesa de la Villa, the Dehesa de Arganzuela or Viveros).
El Retiro is the most visited location of the city. Having an area bigger than 1.4 square kilometres (350 acres; 140 hectares; 0.54 sq mi), it is the largest park within the Almendra Central, the inner part of the city enclosed by the M-30. Created during the reign of Philip IV (17th century), it was handed over to the municipality in 1868, after the Glorious Revolution. It lies next to the Royal Botanical Garden of Madrid.
Located northwest of the city centre, the Parque del Oeste ("Park of the West") comprises part of the area of the former royal possession of the "Real Florida", and it features a slope as the height decreases down to the Manzanares. Its southern extension includes the Temple of Debod, a transported ancient Egyptian temple.
Other urban parks are the Parque de El Capricho, the Parque Juan Carlos I (both in northeast Madrid), Madrid Río, the Enrique Tierno Galván Park, the San Isidro Park as well as gardens such as the Campo del Moro (opened to the public in 1978) and the Sabatini Gardens (opened to the public in 1931) adjacent to the Royal Palace.
Further west, across the Manzanares, lies the Casa de Campo, a large forested area with more than 1,700 hectares (17 km2; 4,200 acres) where the Madrid Zoo, and the Parque de Atracciones de Madrid amusement park are located. It was ceded to the municipality following the proclamation of the Second Spanish Republic in 1931.
The Monte de El Pardo is the largest forested area in the municipality. A holm oak forest covering a surface over 16,000 hectares, it is considered the best preserved mediterranean forest in the Community of Madrid and one of the best preserved in Europe. Already mentioned in the Alfonso XI's Libro de la montería from the mid-14th century, its condition as hunting location linked to the Spanish monarchy help to preserve the environmental value. During the reign of Ferdinand VII the regime of hunting prohibition for the Monte de El Pardo became one of full property and the expropriation of all possessions within its bounds was enforced, with dire consequences for the madrilenians at the time. It is designated as Special Protection Area for bird-life and it is also part of the Regional Park of the High Basin of the Manzanares.
Other large forested areas include the Soto de Viñuelas, the Dehesa de Valdelatas and the Dehesa de la Villa. As of 2015, the most recent big park in the municipality is the Valdebebas Park. Covering a total area of 4.7 km2 (1.8 sq mi), it is sub-divided in a 3.4-square-kilometre (1.3 sq mi) forest park (the Parque forestal de Valdebebas-Felipe VI), a 0.8-square-kilometre (0.31 sq mi) periurban park as well as municipal garden centres and compost plants.
Climate
Madrid has a cold semi-arid climate (Köppen BSk), transitioning to a Mediterranean climate (Csa) in the western half. Madrid's climate has continental influences.
Winters are cool due to its altitude, which is approximately 667 m (2,188 ft) above sea level and distance from the moderating effect of the sea. While mostly sunny, rain, sporadic snowfalls and frequent frosts can occur between December and February with cooler temperatures particularly during the night and mornings as cold winds blow into Madrid from surrounding mountains. Summers are hot and sunny. In the warmest month, July, average daytime temperatures range from 32 to 34 °C (90 to 93 °F) depending on location, with maxima commonly climbing over 35 °C (95 °F) and occasionally up to 40 °C during the frequent heat waves. Due to Madrid's altitude and dry climate, humidity is low. Diurnal ranges are often significant, particularly on sunny winter days when the temperature rises in the afternoon before rapidly plummeting after nightfall. Madrid is among the sunniest capital cities in Europe.