Image caption Former health worker Tareena Shakil was convicted of trying to join IS

The BBC has been given rare access to the work of the Counter-Terrorism Division of the Crown Prosecution Service as it brings an increasing number of cases against Britons accused of terrorism. How is this complex battle fought?

Over a hundred people have now been convicted of offences linked to Syria and Iraq.

The self-styled Islamic State's caliphate - created three years ago - may be shrinking but it continues to inspire its supporters overseas.

In recent months there have been three violent, Islamist-inspired attacks and five thwarted plots in the UK and the director of public prosecutions warns more attacks could occur.

The CPS headquarters are in a nondescript office overlooking the River Thames. For security reasons we have been asked not to identify the floor of the building. Nor can we name the lawyers who agreed to talk to us about their work.

Theirs is often a grim task, observing the gruesome actions of a movement that is expert at online self-promotion.

"Beheading videos, someone being executed out in Iraq, decapitated bodies." A female lawyer, who we will call Christine, lists the atrocities she has had to watch on her laptop. Everyone has different coping mechanisms, she says. What's hers? "Chocolate," she says.

"Some of it is absolutely horrific," adds her colleague John (not his real name) as he leafs through one of his case files, pausing to point out "images that when you come across them you recoil from the page".

These CPS lawyers support two teams of specialist prosecutors who guide cases through the courts. Their numbers have doubled to a total of 18 as a result of the increasing workload.

Image caption The Crown Prosecution Service has its headquarters by the Thames

That was before the terror attacks in Westminster, Manchester and at London Bridge. The plots that have been allegedly stopped in the same period will mean more cases in the courts. Many end up at the Old Bailey whose iconic scales of justice statue can be glimpsed across the water.

Does the CPS have the resources to cope? Director of Public Prosecutions Alison Saunders say it does.

The BBC has spent the last two years gathering details of cases across the UK where Britons have been drawn into the civil war in Syria and Iraq. It is the most comprehensive public document of its kind, listing more than 150 profiles of people who are there or have been killed there and over 100 who have been convicted of offences related to the conflict.

"The numbers have just been incredible," says John, particularly after IS declared the creation of a caliphate and urged Muslims to travel out to defend it.

Is there a typical convicted terrorist? No, says John, they come in different guises although "the majority are relatively young men".

But there are also growing numbers of women drawn to the dark subculture of violent Islamism. The BBC's research shows that about a sixth of those prosecuted for terrorism in British courts over the past two years have been women.

Find out more

Christine says those women and girls who have travelled to Syria "are not necessarily going out to participate in acts of terrorism - they are going out to support the people that are". That makes it slightly difficult to decide how to prosecute them.

Last year a former health worker from the West Midlands, Tareena Shakil, became the first woman to be convicted of joining IS. She had taken her toddler son to Turkey, telling friends and family that she was going on holiday. In fact she slipped across the border into Syria in October 2014.

Birmingham Crown Court heard how she had previously made contact online with IS militants who had already travelled from the UK. One of them told her: "Look sister, by staying in England, you're hanging over the gates of hell. If you die that's where you're going."

Once in the Syrian city of Raqqa, she posted images of her child wearing an IS-branded balaclava and next to an automatic firearm. In a text to the husband she had abandoned in the UK, she said: "I want to die here as a martyr… if you don't like Isis, I won't talk to you anymore."

Image caption Tareena Shakil posted pictures from Raqqa of herself and her son with IS headwear and a gun

But within a few months Shakil had a change of heart. During her trial she described how she took a taxi through several checkpoints on the edge of IS-controlled territory. She picked up her son, "grabbed the nappies and ran across the fields - there were three IS fighters but they had their backs to me, they didn't see me". She managed to make it over a barbed wire fence and across into Turkey.

The judge at her trial accepted she was vulnerable but he jailed her for six years, telling her "you were well aware that the future which you had subjected your son to was very likely to be indoctrination and thereafter life as a terrorist fighter".

Fortunately, Tareena Shakil's story is not typical. What may surprise people is how the vast majority - over 85% - of those convicted in the UK of terrorism linked to Syria and Iraq have never been there. Many plotted to go but were arrested before putting their plans into action.

Others have been convicted of using social media to encourage support for banned groups such as Islamic State. "Cases like that take a long time to build up. We scrutinise the evidence very, very carefully," says Christine, aware of the fine distinction between offensive speech and that which crosses the line into illegality.

Under the Code for Crown Prosecutors the lawyers have to ask if there is a realistic prospect of conviction and whether prosecution is in the public interest. Christine admits to sometimes agonising over these decisions but she says that colleagues will feed in their thoughts. Decisions on terrorism prosecutions will often be signed off by the attorney general.

But there are concerns that the definition of terrorism has been expanded to include activity that shouldn't be regarded as criminal. Recently a Kurdish political activist living in London was cleared at the Old Bailey of disseminating terrorist publications after handing out copies of a Turkish political magazine in Wood Green.

Image caption Alison Saunders, the director of public prosecutions

There is criticism too about whether the increasing levels of secrecy in terrorism cases in British criminal courts is undermining the ancient principle of justice being "seen to be done". National security has been invoked in a growing number of trials, which has sometimes led to the public and press being locked out of courtrooms.

Alison Saunders says the jury get to hear all of the evidence but sometimes "we have to be very careful about what we reveal because we need to protect our intelligence capability and techniques. Otherwise we will not be able to protect society in future."

In the aftermath of recent terror attacks there have been calls for a change of approach. The UK's most senior anti-terrorism police officer, Mark Rowley, has said: "Where we have to step in to disrupt a potential attack before we have the best evidence, we need longer sentences for those convicted."

Prime Minister Theresa May has promised to set up a commission for counter-extremism as part of a battle aimed at "stamping out" violent ideology across society. But what is extreme and who decides?

A much vaunted counter-extremism strategy, developed when Mrs May was home secretary, ran into the sand in the last parliament amid widespread concerns it was unworkable.

Ms Saunders isn't clear how new laws in this area would help. "Our terrorism laws are extremely comprehensive," she says. "We do prosecute people for extreme views."

One of their biggest successes in recent years was the conviction of the hate preacher Anjem Choudary, although there was widespread concern that it didn't happen earlier.

More from the BBC

Image copyright Getty Images Image caption The now-convicted preacher Anjem Choudary

The scale of the challenge faced is shown in the data. The youngest person convicted was a boy from Blackburn who was just 14 when he plotted online with an Australian jihadist to carry out a beheading.

The oldest was a 63-year-old driving instructor from Luton who handed out leaflets in support of IS on London's Oxford Street. Students have fallen foul of the law, as has a hospital director, a trainee teacher and the son of a police officer.

Those convicted include married couples, siblings, a mother of six and a man who faked his own death in a doomed attempt to secretly slip back into the UK. In Syria he had posed for pictures holding a bag of severed heads.

The most serious cases have been IS-inspired plots to kill people in the UK. John opens up a file called Operation Lanosity in which Londoner, Nadir Syed, 22, was convicted of plotting to carry out a beheading around Remembrance Day 2014. There is page after page of graphically violent imagery.

Syed, who was obsessed with the murder of Drummer Lee Rigby in Woolwich, was arrested hours after buying a 30cm chef's knife.

Image copyright Metropolitan Police Image caption Nadir Syed, convicted in 2015 of plotting an IS-inspired terror attack on Remembrance Sunday

The murder of eight people at London Bridge has highlighted yet again the devastating impact of low-tech attacks mounted by people under the spell of a pernicious ideology.

In recent years much of the focus of discussion on the UK terror threat has been on those who return from Syria and Iraq. But some have speculated that the London Bridge attackers may have been drawn to violence on British streets because they were stopped from travelling to the Middle East.

It's a danger Ms Saunders is aware of. "We need to be acutely aware that if people can't go to Syria - and we have certainly seen this in some of the cases we have prosecuted - they may plan... an attack here instead or they may do more to radicalise other people here."

Has enough attention been paid to other incubators of violent extremism - such as Libya - where it is believed the plot was hatched to bomb the Manchester Arena? Large numbers of Britons went out to join the fighting against Col Muammar Gaddafi who was deposed in 2011.

Another striking feature of the stats is the prominence of geographical clusters in which small, radical sub-cultures have developed, nurtured by friendship and kinship. From these have come angry and willing recruits for Islamic State.

Friends and siblings have often travelled together to Syria, each sustaining the other on a collective mission, feeding each other's belief that they could change the course of history. Others have committed offences closer to home.

And extremism sometimes manifests in surprising locations, involving families you might not imagine would be drawn into a conflict in another part of the world.

When an email headed "New Life" dropped into her inbox, Church of England minister Sue Boyce eagerly opened it, desperate for news from its author, her son Jake.

He hadn't been in touch for several months after leaving home in Walsall and then announcing he was about to cross from Turkey into Syria.

Image caption Jake Petty - one of 850 jihadists who have travelled from the UK to the Middle East

The email confirmed her worst fears.

Petty - who was a convert to Islam - had received military training and was now a fighter with IS.

"Nobody has brainwashed me or tricked me into this," he wrote. "You know that I am not bloodthirsty or have a love of violence. It's just in Islam, we are supposed to be one united community and whether my brother is being oppressed in Walsall or Iraq is no difference."

Petty is one of the 850 jihadists who have travelled from the UK to join jihadist groups in Syria and Iraq. About 130 of them have since been killed.

Perhaps more astonishing is that he is not the only young man from Walsall to fight and die for IS in the Middle East. Two of his friends have died there. Two more are believed to be fighting and seven others are in jail for committing offences related to the conflict.

You might ask what is happening in Walsall? But Walsall is not unique.

When you start mapping the data we have collected you see some striking facts.

In addition to the Walsall cluster, there are 91 people from London, 19 from Luton, 17 from Manchester, 15 from Birmingham, eight from Portsmouth, seven from Cardiff, six from Coventry and four from Brighton.

"Humans are social animals. They join movements or political parties or football clubs or the military. Joining the jihad is no different," says anthropologist Scott Atran, founder of Oxford University's Centre for the Resolution of Intractable Conflict and a student of terrorist networks for decades.

This is a point worth remembering because too much emphasis has been placed on virtual networks in the recruitment process. Mr Atran says that only a fifth of IS recruits from the West have been recruited online: "Young people are hooking up peer to peer. They talk to one another. They psyche one another up."

When Sue Boyce recovered from the shock of the email from her son, she contacted MI5. This triggered a major police and intelligence operation uncovering the Walsall cell and eventually leading to a string of convictions in the courts.

But what the trials and statistics can never truly show is the depth of misery endured by the victims of the surge in IS recruitment, whether it's people killed at their hands or shattered families back at home.