Although it is believed that the Roman Empire founded a settlement where the city of Madrid currently lies, the first documented records of Spain’s capital date back to the ninth century AD, when the Iberian Peninsula was occupied by the Moors. At that time, Muhammed I was emir of Córdoba from 852 to 886. He commissioned the construction of a fortress on the banks of the Manzanares River and called it “Mayrit”.
The stronghold was built where the Royal Palace of Madrid presently sits. The citadel was strategically built on top of a hill, with views over the Guadarrama sierra. From this location, the Moors could organize incursions against the northern Christian kingdoms.
The meaning of “Mayrit” isn’t completely clear, although it seems to be the hybrid of two place names; “matrice” meaning fountain in Mozarabic language and “majrà”, meaning riverbed or course of a river in Arabic. Both words refer to the abundance of water, rivers and groundwater there was in this part of Spain.
The citadel was temporarily conquered by Ramiro II in 932, but the Moors managed to reconquer the castle until they were overthrown by Alfonso VI of León and Castile in 1085, on his way to occupy Toledo.
Favored by the monarch’s measures to repopulate the territory, particularly by the compilation of laws called Fuero from 1202, the city began to grow around the fortress during this period.
In 1339 and 1340, Alfonso XI convened the court of the Kingdom of Castile (Cortes del Reino de Castilla) in Madrid, as Henry III of Castile would also do.
Madrid did not become an influential city until Philip II of Spain transferred the capital from Toledo to Madrid in 1561. When the Court had been moved, it became patent that urban reforms were needed and soon suburbs grew outside its Medieval walls.
The number of inhabitants grew from 4,060 in 1530 to 37,500 in 1594. In April 1637, there were 1,300 “legitimate poor and disabled” people and 3,300 beggars in the Courts. Most of them were foreigners, former soldiers and pilgrims from Santiago de Compostela in Galicia. These made up, along with, the swindlers and ruffians, the bottom of Madrid’s social pyramid. The population’s discontent due to the lack of bread and rise of prices was exploited by certain parties to encourage riots, for example The Riots of the Cats in Madrid.
The royal court attracted many Spanish and foreign artists and the city became the artistic and literary hub in Spain. The most impressive buildings of Madrid de los Austrias, name used for the old city center, include the Plaza Mayor, the Town Hall, some churches and the court jail.
During the eighteenth century, Madrid took part in the War of the Spanish Succession, caused by the death of Charles II, who died without an heir. The empire was sought after by the royal houses of Austria (Habsburg), France (Bourbon) and Bavaria (Wittelsbach). Madrid had supported the Bourbon family since 1706 and when Louis XIV of France (House of Bourbon) finally sent his grandson to Madrid to become King Philip V of Spain, the country was led by a member of the House of Bourbon.
As a way of thanking Madrid for its support, Philip V commissioned new palaces and buildings, including the Bridge of Toledo, the Royal Palace of Madrid (1737), which was built to replace the Royal Alcazar, destroyed in a fire in 1734. Ferdinand VI of Spain and especially Charles III put great efforts to modernize the city, for example, by cleaning the streets, installing stone pavements, introducing streetlights and employing people to survey the streets at night, among many other interesting measures. Charles IV continued with these reforms, but on a smaller scale.
Madrid’s society also changed, it became more open with artisan and liberal families and was no longer jumbled and multifarious. Nevertheless, the lower classes were still exposed to periodic famines and their discontent was used to organize political conspiracies, like the Esquilache riot (March 1766) and the Mutiny of Aranjuez (1808). That same year, Madrid’s working classes would fight against the French on the 2 May in the Dos de Mayo uprisings.
The efforts made by the Bourbons to transform Madrid into a modern and developed city were interrupted by the Napoleonic Wars. The city didn’t fully recover until the 1830’s.
Between 1840 and 1850, many old convents and church-owned estates that had been bought by traders, landowners, liberal workers and financiers due to the Desamortización Eclesiástica of Mendizábal in 1836 (Mendizábal's confiscation of church-owned property) were demolished and new neighborhoods were established. However, Madrid was practically the same size it had been during the Habsburg period.
Madrid’s population did not increase thanks to the city’s industrialization, since most of the industrial companies in the twentieth century were still very traditional and only met the city’s requirements. From 1920 onwards, there was an important demographic increase due to immigration and in 1930, 46,9% of the capital’s inhabitants had been born outside Madrid.
After World War II, Madrid, besides being a key consumer market, went through a period of modernization in which large companies were set up and certain industries like the chemical-pharmaceutical, metallurgical and electromechanical began to develop.
Currently six million people live in Madrid metropolitan area and it is one of the most important cities in Europe.