The Walls of Madrid (Spanish: cerca de Madrid, tapia de Madrid) are the five successive sets of walls that surrounded the city of Madrid from the Middle Ages until the end of the 19th century. Some of the walls had a defensive or military function, while others made it easy to tax goods entering the city. Towards the end of the 19th century the demographic explosion that came with the Industrial Revolution prompted urban expansion throughout Spain. Older walls were torn down to enable the expansion of the city under the grid plan of Carlos María de Castro.[1][2]