Taliban fighters, whom US-led forces spent billions of dollars trying to defeat, are now openly active in 70% of Afghanistan, a BBC study has found.
Months of research across the country shows that the Taliban now control or threaten much more territory than when foreign combat troops left in 2014.
The Afghan government played down the report, saying it controls most areas.
But recent attacks claimed by Taliban and Islamic State group militants have killed scores in Kabul and elsewhere.
Afghan officials and US President Donald Trump have responded by ruling out any talks with the Taliban. Last year Mr Trump announced the US military would stay in the country indefinitely.
The BBC research also suggests that IS is more active in Afghanistan than ever before, although it remains far less powerful than the Taliban.
How much territory do the Taliban control?
The BBC study shows the Taliban are now in full control of 14 districts (that's 4% of the country) and have an active and open physical presence in a further 263 (66%), significantly higher than previous estimates of Taliban strength.
About 15 million people - half the population - are living in areas that are either controlled by the Taliban or where the Taliban are openly present and regularly mount attacks.
"When I leave home, I'm uncertain whether I will come back alive," said one man, Sardar, in Shindand, a western district that suffers weekly attacks. "Explosions, terror and the Taliban are part of our daily life."
The extent to which the Taliban have pushed beyond their traditional southern stronghold into eastern, western and northern parts of the country is clearly visible from the BBC study.
Areas that have fallen to the Taliban since 2014 include places in Helmand province like Sangin, Musa Qala and Nad-e Ali, which foreign forces fought and died to bring under government control after US-led troops had driven the Taliban from power in 2001. More than 450 British troops died in Helmand between 2001 and 2014.
In the areas defined as having an active and open Taliban presence, the militants conduct frequent attacks against Afghan government positions. These range from large organised group strikes on military bases to sporadic single attacks and ambushes against military convoys and police checkpoints.
Attacks registered during the research period happened with varying degrees of frequency - from once in three months (low Taliban presence) to twice a week (high Taliban presence).
For the purposes of the investigation, districts controlled or held by the government are defined as having sitting representation from Kabul in the form of a district chief, police chief and courts.
During the research period, the BBC study found 122 districts (just over 30% of the country) did not have an open Taliban presence. These areas are ranked as under government control, but that does not mean they were free of violence.
Kabul and other major cities, for example, suffered major attacks - launched from adjacent areas, or by sleeper cells - during the research period, as well as before and after.
What is the human cost of militant violence?
Amruddin, who runs a local transport company, lives close to the front line in Baharak district in northern Badakhshan province, where the BBC monitored violence suggesting a medium Taliban presence.
"We live with constant fear. Whenever the government side starts fighting with the Taliban, we're caught in the crossfire, bringing life to a standstill. It's quiet at the moment but the Taliban are still here."
In Taliban-controlled Sangin, father of eight Mohammad Reza, described life as "better" under the militants because there was peace.
"It only got violent when the government forces arrived."
Will I make it back home today?
Karim Haidari, BBC Afghan, Kabul
I haven't been sleeping well this week. It happens every time another tragedy hits our city. "You look old, Dad," says my seven-year-old bouncing into my bedroom to remind me it's his birthday. As if I would forget. I laugh and get up.
As I leave the house I pause to look back at my family having breakfast. Will I make it back home today? Will this be the last time I see them? We all think like this in Kabul now.
My BBC colleagues are waiting in the car. We swap news about the latest attack. One of them, a mother of two young children, starts sobbing. "Sometimes I just wish I could blow myself up to end all this. But I don't want to hurt anyone else."
We can get you counselling if it would help, I say. But she's not listening. The driver switches on the radio, to try to change the mood. A pop song comes on with nonsensical lyrics. It's just another day in Kabul. Just another day of hoping we'll all stay alive.
"People have no choice but to leave their homes, farms and orchards or stay and live with Taliban rule," Mahgul, a teacher from a northern district in Kabul province, told the BBC.
She said her family fled their village in October. They went to seek refuge in the government-controlled district centre, only for her brother to be killed there two days later by a suicide bomber.
To the west of the capital, Jamila, a mother of five, said: "Two Taliban rockets landed in our back garden last month. We live just a few hundred metres from the district chief office. It's not safe here."
During the investigation, evidence of a hike in Taliban taxation across the country was also uncovered. In districts where they are openly present, the militants force farmers, local businesses and even commercial goods convoys to pay them tax while still leaving it to the government to foot the bill for basic services such as schools and hospitals.
"They are charging people for the electricity that we supply!" one chief of a southern district reported.
The BBC's research has been reviewed by the Kabul-based Afghanistan Analysts Network, which has been reporting on Afghanistan since 2009.
Co-Director Kate Clark said: "Such a well-researched investigation into the Afghan war is rare and very welcome. The findings are shocking, but unfortunately not surprising - they ring true as an accurate mapping of the extent of the conflict.
"But it is disturbing to realise that each bit of orange shading on the map translates into lives lost and damaged."
Who are the Taliban?
- The hardline Islamic Taliban movement swept to power in Afghanistan in 1996 after the civil war which followed the Soviet-Afghan war, and were ousted by the US-led invasion five years later
- In power, they imposed a brutal version of Sharia law, such as public executions and amputations, and banned women from public life
- Men had to grow beards and women to wear the all-covering burka; television, music and cinema were banned
- They sheltered al-Qaeda leaders before and after being ousted - since then they have fought a bloody insurgency which continues today
- In 2016, Afghan civilian casualties hit a new high - a rise attributed by the UN largely to the Taliban
How bad is violence in the cities?
Violence has soared since international combat troops left Afghanistan three years ago.
More than 8,500 civilians were killed or injured in the first three-quarters of 2017, according to the UN. Final figures for the year are awaited. The vast majority of Afghans die in insurgent violence but civilians often suffer as the military, with US backing, fights back, both on the ground and from the air.
Although much of the violence goes unreported, big attacks in the cities tend to make the headlines. Such attacks are occurring with greater frequency and the Afghan security forces appear unable to stop them.
During the research period, gunmen stormed the headquarters of Kabul's Shamshad TV, leaving one staff member dead and 20 wounded. IS said it carried out the attack. There were other attacks in Kandahar, Herat and Jalalabad.
In the last 10 days of January three attacks left the capital reeling, with more than 130 people dead. Last May, Kabul experienced the deadliest single militant attack since 2001.
At least 150 people were killed and more than 300 injured when a massive truck bomb was detonated in what was supposed to be the safest part of the city. No group has said it carried out the attack.
The rising toll of violence has left the capital's residents feeling increasingly vulnerable.
How strong is the Islamic State group?
While Islamic State has shown they can hit targets in places like Kabul, they are largely confined to a relatively small stronghold on the border with Pakistan in the eastern province of Nangarhar.
During the research period at least 50 people were assassinated in the provincial capital, Jalalabad. Some of the victims were shot dead and others blown up. Three were beheaded, a hallmark of killings by IS.
"My uncle was assassinated on his doorstep," said businessman Mashriqiwal. "He was a city security official. I had to leave Jalalabad. My home is still there but it is just too dangerous to live in and go out in public."
Local people and officials the BBC spoke to said IS now has a presence in 30 districts - not just in the east but also in places like Khanabad and Kohistanat in the north.
The group is fighting both the Afghan military and the Taliban for territorial control.
During 2017 the number of attacks attributed to the group increased, with many targeting urban centres and often Shia Muslims in sectarian attacks almost never seen before in Afghanistan's 40-year conflict.
IS does not fully control any district at present. However the group has seized parts of the northern district of Darzab, displacing hundreds of people from their homes.
How was the research carried out?
Gathering accurate and reliable data on the conflict has been getting harder since foreign combat troops pulled out and handed responsibility for security to Afghan forces.
Previous assessments of Taliban strength have not always had access to information from every district of the country, and have often carried the caveat they may have underestimated the real situation.
The BBC investigation - conducted during late 2017 - provides a rare snapshot of the security situation in every Afghan district between 23 August and 21 November.
A network of BBC reporters across Afghanistan spoke to more than 1,200 individual local sources, in every one of the country's 399 districts, to build up a comprehensive picture of all militant attacks over that period.
These conversations happened either in person or by telephone and all information was checked with at least two and often as many as six other sources. In some cases BBC reporters even went to local bus stations to find people travelling in from remote and inaccessible districts in order to double check the situation there.
How much territory does the government say it controls?
Presented with the BBC's findings, President Ashraf Ghani's spokesman Shah Hussain Murtazavi said: "In some districts areas may change hands. But if you look at the situation this year [2017/18] the activities of the Taliban and IS have been considerably curtailed.
"The Afghan security forces have won the war in the villages. It is no longer possible for the militants to take control of a province, a major district or a highway. There's no doubt that they have changed the nature of the war and are launching attacks on Kabul, targeting mosques and bazaars."
He added: "My understanding is that the BBC report is influenced by conversations with people who may have experienced some kind of incident maybe for an hour in one day. But the activities and services provided by our local administrations across the districts show that the government is in control in the absolute majority of districts - except for a handful where the Taliban are present."
However, in an acknowledgement of how far security has deteriorated, President Trump agreed last year to deploy 3,000 more soldiers, taking the size of the US force in Afghanistan to about 14,000.
The subject of militant gains and territorial control is disputed.
On the eve of the publication of the BBC study, the US military denied trying to prevent a government watchdog from disclosing the amount of Afghan territory believed to be under the control of the Taliban. In its latest report the Special Inspector General for Afghanistan Reconstruction (Sigar) had said it found the move troubling.
Meanwhile, there is no prospect of an end to the conflict and a new generation of Afghans live in the shadow of violence.
"My kids are not safe outside the family home so I don't let them out," said Pahlawan, a Kabul carpet seller with 13 children.
"They are basically under house arrest. I have built them a school in my warehouse. Their world is walls and carpets. Although we are in Kabul, it's like raising them in a jungle."
Data journalism by Will Dahlgreen. Some names have been changed to protect identities.