The peninsula's occupants – Moors, Spanish, and British – have built successive layers of fortifications and defences including walls, bastions, casemates, gun batteries, magazines, tunnels and galleries.
The peninsula is dominated by the limestone massif of the Rock of Gibraltar, which presents a sheer cliff over 400 metres (1,300 feet) high at its north end, facing the isthmus.
[5] The Irish writer George Newenham Wright observed in 1840 that "the surface of the Rock is wholly occupied by defensive works; where it was possible, and often where it appeared almost impracticable, batteries and fortifications have been formed.
After defeating a Castilian counter-siege which ended after two months, the Marinid sultan Abu al-Hasan Ali ibn Othman ordered a refortification of Gibraltar "with strong walls as a halo surrounds the crescent moon".
[13] Many details of the rebuilt city are known due to the work of Abu al-Hasan's biographer, Ibn Marzuq, whose Musnad (written around 1370–71) describes the reconstruction of Gibraltar.
[24] The town's inhabitants paid the price for this neglect in September 1540 when Barbary pirates from North Africa carried out a major raid, taking advantage of the weak defenses.
[25] A lookout tower, one of several constructed along Spain's southern coast during this period, was built at the eastern end of the isthmus linking Gibraltar with the Spanish mainland.
Fernandez del Portillo noted in 1610 that while Gibraltar was "girt by quite a good wall with bastions at corners", there still remained work to be done to complete the fortification plans that had been drawn up in the previous century.
"[5] The biggest weakness was the lack of an effective sea wall to resist naval bombardments, and in 1618 Philip III of Spain authorised works to create a new mole for a deep-water harbour, protected by a newly constructed gun platform and the Torre del Tuerto fort.
[27] Philip IV subsequently ordered a major modernisation of Gibraltar's fortifications due to hostile activity in the Strait by the Protestant powers of northern Europe – particularly England and the Dutch Republic.
[29] On the north side of Gibraltar, the Muralla de San Bernando (now the Grand Battery) was fully adapted to mount cannon facing the isthmus with the old archery towers being pulled down and replaced by bastions.
[35] Following the siege, the Spanish began the construction in 1730 of the Lines of Contravallation, a fortified structure across the entire width of the isthmus anchored by two major forts on each end.
A marshy area in front of the Landport Gate was flooded and turned into what became known as "the Inundation", a pear-shaped body of brackish water blocked with palisades, underwater ditches and other hidden obstacles to prevent passage.
[41] Skinner and Tyrawley agreed that the most pressing threat was that of a combined land and sea assault focusing on the weakest part of the defences, the open ground between the South Front of the town and Europa Point at the end of the peninsula.
"[42] Skinner disagreed with the placement of the new fortifications and criticised the use of compacted earth and sun-baked bricks, which had enabled them to be built at great speed and minimum cost, rather than stone.
[44] He was strongly supported by Tyrawley's successor as governor, Lieutenant General Edward Cornwallis, who wrote in 1768: Gibraltar has its faults, but, with them, as tenable in my opinion as any place in Europe : where it is vulnerable is the sea .
"[45]Funds were scarce in the 1760s but a number of improvements were made to the North Front defences and the sea wall from South Bastion to Europa Point, which was severely damaged by a great storm in 1766.
[48] To carry out the improvements more efficiently and cheaply, Green raised a Soldier Artificer Company – a predecessor of the Royal Engineers – of skilled labourers under military discipline.
[49] The Spanish historian López de Ayala remarked on how well prepared the garrison was: One of the most noteworthy things about this place is that there is no cannon, there is no mortar or howitzer without its known and predetermined target .
[50] The first of Gibraltar's many tunnels was also constructed, with the original intention of reaching a rocky outcrop called the Notch on the north face of the Rock, to cover a blind angle on the Mediterranean side.
In 1841, General Sir John Thomas Jones of the Royal Engineers conducted a study of Gibraltar's defences which prompted major changes and defined the nature of the fortifications for many years to come.
He proposed that the shoreline artillery should be pulled back some 300 yards (270 metres) to "retired batteries" situated higher up the hill, equipped with the latest and most powerful guns and firing from barbettes rather than through embrasures.
Further batteries and fortifications were constructed around Rosia Bay near the south of the peninsula and Windmill Hill was strengthened around its entire perimeter, with Retrenched Barracks at its north end blocking access to the higher ground behind.
A report by Generals William Howley Goodenough and Sir Lothian Nicholson, the governor at the time, recommended reducing and standardising the guns to make them easier to maintain and supply.
Proposals were put forward to build a new harbour on the east side of the Rock, where ships would be less vulnerable to direct artillery fire from the mainland, but were abandoned due to the vast expense and only marginal gains in security.
The only action seen by Gibraltar's coastal defences during the First World War occurred in August 1917 when the 6-inch gun at Devil's Gap Battery engaged and sank a German U-boat travelling on the surface.
[69] The possibility of an attack from the land was not a theoretical concern, as Adolf Hitler sought Spanish support to carry out Operation Felix, an invasion of Gibraltar that would have enabled the Germans to close the entrance to the Mediterranean to the great disadvantage of the Allies.
They included a hospital, storerooms, workshops, ammunition magazines, a bakery, food stores capable of holding enough rations to feed the entire garrison for sixteen months, a power station, a water distillation plant and a telephone exchange.
The Royal Navy's historic role in the Mediterranean was effectively taken over by the United States Sixth Fleet and Britain's strategic interests shifted to the Atlantic.
The Southport Gates still bear the arms of Charles V, with columns on either side representing the Pillars of Hercules entwined with scrolls reading "plus ultra", the national motto of Spain.