The first stable human settlement located in the area that is now known as Madrid, was a poor small village that emerged during the second half of the 9th century, next to a fortress built by the emir of Cordoba on a hill near the Manzanares River. It was called ?Magerit?, a word deriving from two similar place names: the first, a Mozarab word---?matrice?---means fountain; the second word, ?majira?, is Arab and means riverbed.
Magerit became Christian territory in the year 1085. In 1520 it joined the Communities of Castilla against King Carlos I. After the defeat of the rebels in Villamar, Magerit was occupied by the royal troops.
Philip II settled the royal court in Madrid in the year 1561. Madrid was destined to be the capital of Spain from then on until today, except for a period between 1601 and 1606 during which the court was moved, as a token gesture, to Valladolid.
With the establishment of the court in Madrid the city?s population began to grow quickly, and in 1625 Philip IV had the wall that surrounded the city knocked down in order to make room for more people, and constructed what was to be the final enclosure of the city. This last wall would restrict Madrid?s growth until the 19th century. The government carried out its functions in the Royal Alcazar, where currently the Royal Palace and Plaza de Oriente stand. At the same time the Palace of Buen Retiro was built on the other side of town.
The change of dynasty was a positive thing for the city. Madrid had become a city of dark and narrow streets that were overcrowded and smelly, as there was no sewer system. The Borbones considered that Madrid should live up to the standards of other European cities. The fire in the Royal Alcazar in 1734 (an unfortunate event in which a third of the royal collection of paintings was destroyed) was the perfect excuse to build the Royal Palace, emulating the French rococo and neoclassic styles. Construction continued until the year 1755, and the palace wasn?t inhabited until the reign of Carlos III. It was probably this King who did the most to clean up Madrid and make it more beautiful. He gave orders to build bridges, hospitals, parks, fountains, buildings for scientific use, sewer systems, and was helped by a handful of the best architects and town planners: Francesco Sabatini, Ventura Rodriguez and Juan de Villanueva, to mention but a few. Probably the project for the Prado Hall, on the outskirts of the city between The Buen Retiro Park and the wall surrounding the city, was the most important one, and the one that left the greatest cultural heritage to the city: The Prado and Recoletos Avenues; the fountains of Neptune, Cibeles and Apollo; the Royal Botanical Gardens; The Astronomic Observatory; and The Natural History Archive (today The Prado Museum).
The uprising of Madrid?s working class against the French troops on 2 May 1808 established the beginning of the War of Independence. King Joseph Bonaparte made serious changes in the capital, knocking down churches and convents in order to build town squares, earning him the nickname of el rey plazuelas (The Town Square King). In spite of his involvement in urban development, the events of the war forced him to flee Madrid. The liberation of the city ended in the destruction of important monuments, such as the Palace of Buen Retiro.
During the 19th century, the population of the city continued rising. In 1860 the wall constructed by Philip IV was finally brought down, allowing the city to grow, in an organized way at first thanks to ?The Castro Plan? and plans for urban expansion. In spite of these efforts, at the beginning of the 20th century Madrid still looked more like an old village than a modern city.
During the first 30 years of the 20th century, the population of Madrid reached almost one million. This massive growth brought with it infrastructural demands that encouraged, by way of arterial road and railway links, contact with neighboring small towns, which until then had remained cut off from Madrid.
In the year 1931, before a frenzied crowd in the Casa de Correos located in Madrid?s central square La Puerta Del Sol, the Second Spanish Republic announced its arrival on the scene. In 1936 the Spanish Civil War broke out. A body of citizens, soon militarized as the Popular Army and directed by the Defense Council of Madrid, managed to hold back the enemy at the city?s boundary. The northwestern area of the city where the front had formed (including the neighborhoods of Argüelles and Ciudad Universitaria) were seriously damaged, in clashes known as The Battle of Madrid. However, the city suffered no other attacks during the rest of the war.
The unstoppable expansion of the city continued after the war ended. Hundreds of thousands of Spaniards emigrated from the country to the city. Madrid, along with Barcelona and Bilbao, is one of the cities that most benefited from the voluntary relocation of its citizens. During the 1940s, Madrid annexed up to 14 different bordering municipalities including Aravaca, Barajas, Canillas, Canillejas, Chamartin de la Rosa, Fuencarral, Hortaleza, El Pardo, Vallecas, Vicalvaro, Villaverde, Carabanchel Alto and Carabanchel Bajo. As a result, the area of Madrid increased from sixty-six square kilometers to its current six-hundred and seven.