Considering its size and importance nowadays, it's hard to believe that Madrid was a small and insignificant hamlet until well into the 16th century. Up until then, the most important Spanish city was nearby Toledo, but what King Felipe II wanted was a clean slate to build upon.
There was a Muslim settlement up until the 10th century; it was the Moors who named the Manzanares River "al-Magrit" ("source of water") and called the area Mayrit, from which Madrid derives its name. There was a Moorish fort - or alcazar - where the Royal Palace now stands. While the fort was destroyed, parts of the old Arab walls that once surrounded the town can still be found today. However, in the late 11th century Mayrit was conquered by King Alfonso VI of Castile and taken back under Spanish rule during the early stages of the Spanish Reconquest. From then until Felipe honed in on the spot as the future Spanish capital, insignificant Madrid lived in anonymity and underwent little change.
In 1561 Felipe decided to uproot the royal court and move the whole operation over to Madrid. Basically, capital status wasn't something Madrid achieved over time; instead, the city was literally created to be the capital. It wasn't until the 17th and 18th centuries, however, that Madrid truly began to grow.
Interestingly, while Madrid is a relatively "new" city by European standards, there are remnants of medieval Madrid found throughout the oldest parts of the city, attractions that we will show you on your guided tour of Old Madrid. Medieval Madrid dates back to its Moorish roots as the Morería (Moorish Quarter) and is focused around three plazas: Plaza de la Paja, Plaza de San Andrés and Plaza de la Cruz Verde. In the historic Plaza de la Villa, you can admire the Mudejar-style 15th-century Lujanes Tower and adjoined house. Also nearby is the Iglesia de San Nicolás; built in the 12th century, it's Madrid's oldest church and boasts a bell tower that may have been from a former mosque. Another of Madrid's famous medieval towers is the belfry of the San Pedro el Viejo Church. You can take a look at sections of the ancient Moorish wall down behind the cathedral, stroll along the centuries-old Calle del Toro or seek out the Plaza del Alamillo, which was home to the Arab courts of justice.