The advantageous geostrategic position of the country, rich stocks of raw materials, wealthy cities – all this was the reason for enemies to attack the country of Azerbaijan. In ancient times and the Middle Ages, hundreds of castles and fortresses, some of which survive today, were built to defend against enemies.

In the 5th century, many kilometres of embankments were built to defend against incursions from the north. In the north-east there were three such embankments: the Derbent wall, the Gilgilchai wall and the Beshbarmak wall. To the north-west, there was one embankment: the Zaqatala wall. These embankments that stretched for tens of kilometres protected roads into the deep interior. Signal towers were built, on which fires were lit (in the event of danger) as early warnings before attacks. To this day the Derbent wall and small parts of the Beshbarmak wall and Chirag Gala castle have survived.

Large cities built walls for their defence. Large cities such as Baku, Ganja and Tabriz were protected by two rows of walls. The history of Azerbaijan is rich with examples where the urban population, hidden behind the walls, resisted the enemy forces. Archaeological excavations revealed the defensive walls of Ganja, Shamkir, Beilagan, Gabala towns. To this day, the walls of Baku, Sheki, and Zaqatala have been kept in good condition.

Castles were built in strategically important areas of the country. The Alindzha-Kala fortress, which served from the 5th to the 17th century, was famous for the fact that it resisted forces of Tamerlane (1387-1401) for 14 years. The Gelersen-Görersen fortress became known for the fact that 3 years resisted forces of Nadir Shah (1744-1747) and the enemy could not seize it. In the 14th century, the Sabail fortress (built to defend Baku from attack from the sea) all sank as a result of an earthquake and today only the tips of its towers are visible in the Baku bay.

Under feudalism many feudal castles were built in Azerbaijan. Some of them are still in good condition. Castles in Ramana, Mardakan, Nardaran and Kala municipalities are located not far from Baku and are open to public.