The Ribat of Madrid was a small fortified community built between 860-880 AD by order of Emir Muhammad I. It consisted of a 2 km walled enclosure that housed a castle-fortress, civilian medina, and mosque, home to between 2,000-3,000 people. The Ribat was strategically located on the Manzanares River to defend against Christian conquest. After reconquest, it was expanded and renamed the Royal Alcazar of Madrid, which now occupies the site of the original Ribat as the modern-day Royal Palace of Madrid.