stylistic:tone, information:extraction
Modern Age

During the revolt of the Comuneros, led by Juan Lopez de Padilla, Madrid joined the revolt against Charles, Holy Roman Emperor, but 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 the year 1530 to 37,500 in the year 1594. The poor population of the court was composed of ex-soldiers, foreigners, rogues and Ruanes, 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, the city of 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 accordingly). Being the capital was decisive for the evolution of the city and influenced its fate and 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.

During the early 17th century, although Madrid recovered from the loss of the 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 was however rampant. The century also was a time of heyday for theatre, represented in the so-called corrales de comedias.

The city 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 the 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.