Madrid's origins trace back to the 9th century when the Muslim emir Muhammad I of Córdoba ordered the construction of a fortress on the banks of the Manzanares River to protect nearby Toledo. The settlement, known as *Mayrit*, flourished until 1085, when it was conquered by the Christian King Alfonso VI of Castile during the Reconquista.
For centuries, Madrid remained a relatively modest town. Its destiny changed dramatically in 1561 when King Philip II moved the royal court from Toledo to Madrid, effectively making it the capital of the vast Spanish Empire. The city grew rapidly under the Habsburg dynasty, resulting in the historic "Madrid de los Austrias" district. In the 18th century, the Bourbon kings, particularly Charles III (often affectionately called the "best mayor of Madrid"), modernized the city by paving streets, installing streetlights, and commissioning grand monuments like the Puerta de Alcalá.
The early 19th century brought the Peninsular War. On May 2, 1808, the people of Madrid rose against occupying French troops (the *Dos de Mayo* uprising), sparking the Spanish War of Independence. In the 20th century, Madrid was a focal point of the Spanish Civil War (1936–1939), suffering heavy aerial bombardment and enduring a nearly three-year siege before falling to Nationalist forces.
Following the death of dictator Francisco Franco in 1975, Madrid became the crucible of Spain's transition to democracy. This era birthed *La Movida Madrileña*, a countercultural explosion of freedom, art, music, and film. Today, Madrid stands as a modern, progressive European capital that honors its complex and layered history.

