From the earliest times, walls surrounded cities and palaces, often of enormous thickness and of great height, some were surrounded by a moat, others flanked by towers. Some ancient fortifications date from periods so remote as the walls of Babylon and the curtain wall of Ashur from about 1600 B.C.
The main function of all castles was defense, everything else was secondary. They were always surrounded by a curtain wall, which was often supplemented by a reinforced shield wall at strategic points. Crenellated battlements and arrow slits protected the defenders, and attackers often also had to overcome a series of several gates. The main entrance was protected by a drawbridge and machicolations projecting over the gate, from which boiling liquids and missiles could be dropped on the hapless foes below. The final refuge of the castle residents was the stronghold, or keep. It was the tallest and strongest building within the walls, with a high entrance accessible only via a removable ladder or wooden bridge. In addition to being a watchtower and the centre point of the entire castle, the keep was also a status symbol. The main residential building (great hall) was called the Palas. The castle chapel was often installed in the gatehouse or one of the main towers (nearer my God to Thee!), and a small garden inside the walls provided herbs, flowers and vegetables in emergencies. Offices and service rooms were generally located in the outer ward.
From the 16C on castle walls had to be made increasingly thicker and stronger in response to the development of artillery. Only a few castles were made into mighty fortresses.. Instead, the nobility increasingly moved to more comfortable residential castles, Many, were sumptuously ostentatious and magnificent buildings.
Popular interest in castle ruins began with the age of romanticism. In 1774