Mayrit: How Madrid Began and the Muslim Walls You Can Still See
Madrid began as Mayrit, a 9th-century fortress built for the emir of Córdoba. See where its Muslim walls survive and how it became Christian.

Madrid started as Mayrit (also written Majriṭ), a walled fortress that the Cordobese emir Muhammad I had built on the high left bank of the Manzanares river in the second half of the 9th century. Pieces of its walls still stand next to the Royal Palace, on Calle Mayor and under the Plaza de Oriente, and they are probably the oldest construction left in the city. Christian forces took the town in 1083 or 1085, and it grew into a mid-ranking Castilian town long before it became the capital.
Who founded Madrid, and when?
Muhammad I, emir of Córdoba from 852 to 886, ordered the fortress. A text by the chronicler al-Himyari places the construction of the walls somewhere between 860 and 880, according to the Wikipedia article on the Muslim Walls of Madrid. The site sat on a wide farmed valley with easy access to water, and the citadel (the almudaina) stood where the Royal Palace is today.
Mayrit began as a military post where troops were quartered. It was one of several fortresses north of the Tagus river that watched the route along the Manzanares between the Sierra de Guadarrama and Toledo. Those forts made it harder for the Christian kingdom of Asturias to send help to Toledo, a city that often rebelled against Umayyad rule. Other strongholds in the same defensive chain stood at Talamanca de Jarama, Alcalá de Henares and Villaviciosa de Odón. Mayrit was one post among many, which is one reason the chronicles mention it so rarely.
What was Muslim Madrid like?
Inside the walls stood three main buildings: the alcázar (fortress), the mosque and the house of the emir or governor. The Wikipedia article on the history of Madrid describes the settlement as the alcázar plus a wider walled citadel, al-Mudayna, with some houses outside the walls, covering roughly 8 ha. The most generous estimates for the 10th century put the population at about 2,000. Figures for the walled area differ between sources: the article on the walls gives about 4 hectares inside a circuit of about 980 meters.
The walls ran south from the alcázar. The other sides needed little building because the cliffs above the Manzanares protected the west and the ravines of the Arenal brook guarded the north and east. A moat existed only on the eastern section. There were three gates, which channelled traffic and helped with tax collection, and the busiest streets ran through them. In the 17th century the historian Jerónimo de Quintana described the walls as strong masonry and mortar, twelve feet thick, with towers and moats.
Up to the proclamation of the Caliphate of Córdoba, a family called the Banū Sālim held local power. Caliph Abd-ar-Rahman III had the walls reinforced after Ramiro II of León advanced in 932, and in 977 Almanzor used Mayrit as the starting point of a military campaign. By the late 10th century the town was a frontier stronghold valued for its closeness to Toledo.
Where does the name come from?
Mayrit is the first recorded name of the city. The 10th-century Cordobese chronicler Ahmad ibn Muhammad al-Razi mentions the Castle of Madrid and places it in the district of Guadalajara. After the Christian conquest, the geographer Al-Idrisi described Madrid in the first half of the 12th century as a small city and a solid, well-populated fortress that had a small mosque in Islamic times. Later Muslim writers assigned it to Toledo instead, which may mean the town changed districts after the civil war that broke up the Caliphate.
Another name from this period survives in the cathedral. After the conquest, the mosque became the church of the Virgin of Almudena, a name taken from almudin, the garrison’s granary. Tradition says the image of the Virgin was found in 1085 in the walls near the Puerta de la Vega gate.
How did Mayrit become a Christian town?
The town changed hands during Alfonso VI’s campaign for Toledo. Historians still argue whether it fell in 1083, through negotiations between Alfonso VI and al-Qadir, or in 1085 as a result of the capture of Toledo. Part of the Muslim population stayed, alongside a large Mozarabic (Christian Arabic-speaking) community, and settlers came mostly from Castile and León. The Christians then built a wider ring, the Christian Walls of Madrid, so the town kept its defensive role.
By the end of the Middle Ages Madrid had one of the 18 votes in the Cortes of Castile. Kings of the Trastámara family stayed there often, and Henry IV died in the town. The move that made Madrid the capital came later, and our guide to why Philip II moved the royal court to Madrid picks up the story there.
Where can you see the Muslim walls today?
The walls were declared an Artistic-Historic Monument in 1954. These are the remains the sources list:
- The park of Mohamed I, named after the founder, where the walls themselves stand.
- Calle Mayor 83, beside the viaduct over Calle de Segovia: ruins of the Torre de Narigües, probably a tower set apart from the main wall and joined to it by a lower wall, used as a lookout.
- Plaza de Oriente underground car park: the base of the watchtower known as the Torre de los Huesos (Tower of the Bones) is on display.
- Plaza de la Armería, between the Royal Palace and the cathedral: a section about 70 metres long was uncovered between 1999 and 2000 during work on the Royal Collections Gallery. It may match the Puerta de la Sagra, one of the gates.
Some remains were lost in the 20th century. Walls near Calle de Bailén 12 disappeared when an apartment block went up, though some were built into its foundations. The redesign of the Plaza de Oriente, finished in 1996 under mayor José María Álvarez del Manzano, uncovered many remains and then removed them.
Tips for visiting
All the sites are within a short walk of each other, so one route covers them: start at the Calle Mayor and Calle de Segovia viaduct, walk to the park of Mohamed I, then go on to the Plaza de la Armería and the Plaza de Oriente. Opening times for the Royal Collections Gallery and access to the car park display change, so check them on the official pages before you go. If you are flying in, our guide to getting from Barajas airport to the city covers the Metro, bus, train and taxi options.
Quick answers
What is the oldest building in Madrid?
The Muslim walls from the 9th century are probably the oldest construction still standing in the city.
What was Madrid called before it was Madrid?
Its first name was Mayrit, also written Majriṭ, the Arabic name of the fortress built for Muhammad I.
When did Christians take Madrid?
In 1083 or 1085. Historians disagree on whether it came before the fall of Toledo or as a result of it.
Why is the cathedral called Almudena?
The name comes from almudin, the granary of the Muslim garrison; the old mosque became the church of the Virgin of Almudena.
Checked against official sources in November 2026. Hours, prices and rules change: confirm on the official page before you go or apply.



