Spain ceded Gibraltar to Britain in perpetuity in 1713 following a military struggle but has since the 1960s fought to have the territory returned to Spanish sovereignty.
Tensions between Britain and Spain over the tiny territory have resurfaced over a concrete artificial reef built by Gibraltar in July. Madrid has said it is considering raising the dispute over its sovereignty with global bodies such as the United Nations.
But Britain is determined to keep Gibraltar for communications and intelligence reasons and to monitor traffic in the Strait of Gibraltar which separates Europe from Africa, said Alejandro del Valle, an international law professor at Spain's Cadiz University.
"You can't forget that much of the territory is occupied by a military airbase, a naval base that is essential for stopovers and as a place to repair nuclear submarines as well as an intelligence base," he said.
Military facilities are located at Gibraltar's airport, at the end of the runway which visitors to the British outpost must cross either by foot or by car to enter the tiny city.
The self-governing British overseas territory, measuring just 6.8 square kilometres, is home to about 30,000 people, and overlooks the only entrance to the Mediterranean from the Atlantic Ocean.
During World War II, Britain's military based in Gibraltar controlled virtually all naval traffic in and out of the Mediterranean Sea.
Its location is still strategic given its proximity to Africa's Sahel belt, where Islamist extremism is on the rise, and the fact that a large amount of Middle Eastern oil and gas that is consumed in Europe crosses the Mediterranean, said Del Valle.
A British naval base in Gibraltar, once the mainstay of the territory's economy, is now home to fewer than 200 marines but it remains a popular stopping point for ships heading to the Mediterranean.
"It is a permanent port of call throughout the year for frigates as well as nuclear submarines from Britain as well as from the United States on their way to and from patrols in the Mediterranean," said Luis Romero, a Spanish security expert and the former editor of Europa Sur, a daily newspaper published in Algeciras near Gibraltar.
"A British military commander in Gibraltar said several years ago: 'If Gibraltar did not exist we would have to invent it, because here we are one thousand miles closer to the threat'," he added.
British warships have embarked on a routine naval exercise that will see a frigate, the HMS Westminster, dock in Gibraltar .
The stop comes amid an escalating diplomatic row between London and Madrid over stringent car searches by Spanish guards at the Gibraltar border.
Gibraltar is more important now for shipping than for its military role, said Chris Grocott, a lecturer in economic history at the University of Leicester who specialises in Gibraltar.
"Historically it was an incredibly important military base. It is less so now. When you look at the kinds of military operations Gibraltar was involved in the past, like World War II, these were clearly enormous military operations of a scale that does not happen anymore," he said.
"In terms of its position I think it is more important for its place on the shipping lane, as a refuelling stop."
Britain also values the key role Gibraltar plays in its electronic surveillance operations, said Romero.
The Rock of Gibraltar, a massive limestone block whose white cliffs rise up to more than 400 metres above the sea, "is a very interesting watchtower for the British, who exploit it for their own benefit as for that of its closest ally, the United States," he said.
Gibraltar's strategic importance to Britain was underscored during London and Madrid's failed talks on joint British-Spanish sovereignty in the early 2000s, said Del Valle.
"The British of course did not want co-sovereignty for the bases or that they be for joint use," he said.