Image copyright MOD Image caption The Union flag had been flying in Helmand since 2006

After 13 years, eight of them involving bloody fighting in Helmand, Britain's war in Afghanistan is finally over.

In a ceremony at the main British base at Camp Bastion, the union flag was lowered and the camp was handed over to the Afghans who will be left behind to look after their own security in what has been one of the hardest provinces to tame.

Bastion was once the largest British military base in the world - a sea of tents, shipping containers and barricades, plonked on the flat, empty, red Helmand desert like the first city on Mars.

At its busiest, Bastion housed up to 14,000 troops. Its 2.2-mile (3.5km) runway was like any busy airport - at the height of the fighting it witnessed up to 600 aircraft movements a day. Its perimeter wall was more than 20 miles long.

It had its own hospital and water bottling plant, as well as shops, canteens and gyms.

Image copyright MOD Image caption Bastion was as big as Reading in area

It was a military metropolis from which the British, and later the US Marine corps and Afghans too, directed the fight in Helmand - the hub from which UK forces re-supplied more than 100 smaller bases at the height of the war.

Those have now all gone, and the British presence in Bastion has been almost completely erased.

Even Bastion's memorial wall, which bears the name of each of the 453 British military personnel killed in the conflict, has been removed. It will be rebuilt at the National Arboretum in Staffordshire - not just closer to home, but more secure. Helmand is still one of the most dangerous places in Afghanistan.

'Worth the hurt?'

So what might the British leave behind in Afghanistan after a presence of 13 years? What do they have to show for a war that has cost more than £20bn and hundreds of precious lives?

The British military believe they will be leaving Helmand in better shape than when they arrived.

Across the country, 6.7 million children now attend school, nearly half of them girls. That would have been unthinkable under the Taliban rule. Healthcare has improved; life expectancy is longer.

Image copyright Getty Images Image caption David Cameron visited Bastion earlier in October

But corruption is still rife and violence, though suppressed, still threatens to tear the country apart.

Measuring success is perhaps hardest for those who lost loved ones here.

Robert Foster died in Helmand in 2007. The 19-year-old private was killed when an American warplane mistakenly dropped a bomb on his position.

His father John says: "Seven years on, I still struggle with the fact that my son and his mates were killed in a conflict that should never have happened."

He describes himself as being proud of what Robbie did: "I try to hold in my heart that my son and his mates thought they were doing the right thing," he says.

He also accepts that the country is now more stable, but he wonders for how long. The Taliban have already moved back into some of the areas once occupied by the British. John asks: "Was it worth all the hurt caused to so many?"

'Muddled through'

As this long war draws to a close, it's the question that hangs in the air: "Was it worth it?"

Many in the military believe it is too soon to tell; they are more reluctant to rush to judgement, when they witnessed comrades die and suffer life-changing injuries.

It's harder still for those who ordered men into battle. Andrew Mackay was the commander of British forces in Helmand in 2007. After reaching the heights of major general, he resigned his commission - in part out of frustration over the way the war in Afghanistan was conducted.

Looking back, he now says: "We should have done so much better." There was confusion from the start about the mission. Was it nation building, counter-insurgency or counter-terrorism?

As for counter-narcotics, he says: "It's a nonsense to suggest we were there to stop heroin getting to the streets of London." Today poppy production in Afghanistan is at record levels.

The failure to explain must ultimately lie with the politicians in charge. But there were failings by the military too. In the early days there was a switch in tactics every six months as a new brigade commander arrived with a fresh batch of soldiers, often eager to prove themselves in battle.

In the early days commanders did complain about not having enough men and the right equipment, but that did not seem to affect their desire to "get the job done".

Mr Mackay says: "We muddled through for far too long".

'Manipulated'

Pacifying Helmand was always going to be tough. The largest province in the country, it was remote, rural and lawless. It had long been a Taliban stronghold and centre of the drugs trade. Added to that, the British empire had history in Helmand.

The locals still remembered their victory at nearby Maiwand in 1880 during the second Anglo-Afghan war. The returning British may have forgotten, but the Pashtuns of the south had not.

Nor did the British really know what they were getting themselves into when they re-entered Helmand in 2006.

Dr Mike Martin, an academic and former army reservist, describes how they were "manipulated" by local tribes to settle old scores with rivals. He was one of the handful of officers who served in Helmand who was able to speak fluent Pashto.

Camp Bastion

Image copyright PA

Bastion was a sprawling, well-fortified British-run base the size of the town of Reading and home to 30,000 people

It had its own water bottling plant, hospital, police force and even a Pizza Hut

It was widely regarded as a safe haven for troops

However, in 2012 a Taliban attack breached the perimeter and resulted in the death of two US Marines

Its airfield was busier that either Luton or Stansted in terms of aircraft movements including helicopters

Source: BBC/MoD

Inside Camp Bastion

He argues the British took far too long to understand the people they were trying to win over and "were trying to turn the war into something it was not".

Many still hold out hope for Afghanistan's future. It has just witnessed relatively peaceful elections and a transition of power. But there are also those who conclude the war was a mistake.

'Dented confidence'

Richard Streatfeild served as a major in the Rifles in Sangin where the British suffered some of their heaviest losses. He arrived as a believer in the mission, but left with many doubts.

In his book Honourable Warriors, he concludes: "Any reading of the culture, the history or politics should have prevented us from taking on Helmand."

As the British now prepare to leave for good, he says: "It may be dressed up as victory, but it will be the paint on the grave."

Whatever legacy Britain leaves behind in Helmand, Afghanistan already appears to have had an impact on British foreign policy and any future military intervention.

Mr Mackay asks the question: "Has it dented our confidence so much that we can not longer put boots on the ground?" Looking at the responses to the crises in Syria and Iraq, his answer is "yes".

Maj Gen Andrew Mackay's Afghanistan: The Lessons of War will be broadcast on BBC Radio 4 at 20:00 GMT on Tuesday 25 November