It was the place for the local leader to live and as a defense when the city was under attack. A kasbah has high walls which usually have no windows. Sometimes, they were built on the top of hill to make them easier to defend. Some of them were also placed near the entrance of harbors.
Having a kasbah built was a sign of wealth of some families in the city. Almost all cities had their kasbah, this building being something necessary for the city to survive. When colonization started in 1830, in northern Algeria, there were a great number of kasbahs that lasted for more than 100 years.
A Kasbah may also describe the old part of the city, in which case it has the same meaning as a medina quarter. The Spanish word alcazaba is a cognate naming the equivalent building in Andalusia or Moorish Spain.