Image copyright AP Image caption Taliban fighters took control of the provincial capital of Kunduz in September

The Afghan government and its US and Nato allies have been fighting the Taliban in Afghanistan for the past 14 years.

But, despite the killing of thousands of militants, the insurgent group has retaken big chunks of the country.

There are three main reasons for this resurgence.

First, the end, in 2014, of the US and Nato combat mission and the withdrawal of most foreign forces from Afghanistan reduced the risk the Taliban faced of being bombed and raided.

The group was further emboldened by the comparative lack of interest from the international community and the diversion of its attention to crisis in other parts of the world, such as Syria, Iraq and Ukraine.

As the Taliban have overrun military bases, district centres and security check-points in different parts of Afghanistan, they have seized more weapons and have been using them in their fight against Afghan government forces. They have also captured dozens of Humvees and police vehicles, which they now drive in areas under their control.

Secondly, the Pakistani military's Operation Zarb-e-Azb, launched in the North Waziristan tribal area in June 2014, dislodged thousands of mainly Uzbek, Arab and Pakistani militants, who flooded into Afghanistan and swelled the Taliban's ranks.

The Taliban also reportedly moved a big number of their own fighters from Pakistan.

Media playback is unsupported on your device Media caption The BBC has obtained rare footage of the Pakistani army's strikes on the Taliban in North Waziristan, as Andrew North reports

And finally, although the Afghan security forces have fought well against the insurgents over the past year, they lack certain capabilities and equipment especially air power and reconnaissance.

The political infighting in the central government in Kabul and the apparent weakness in governance at different levels is also exploited by the Taliban.

Foreign fighters

The presence of several thousand foreign fighters has further complicated the situation.

Afghan government officials said in June 2015 there were more than 7,000 foreign militants in Afghanistan. The Taliban have been bolstered by militants from the Middle East, Central Asian countries and Pakistan.

About a dozen militant groups, having different goals and agendas, are fighting in Afghanistan. A few of them have challenged the Taliban's supremacy, but most of them are directly or indirectly supporting the Afghan Taliban with money and/or manpower.

The emergence of so-called Islamic State (IS) also brought the Taliban and al-Qaeda closer, as never before, by challenging the legitimacy of both groups.

Although the priorities and strategies of the Taliban and al-Qaeda are different, the two groups have been helping each other in Afghanistan, while IS has tried to undermine both groups.

The al-Qaeda leader, Ayman Al-Zawahiri, renewed his pledge of allegiance to the Taliban's new leadership and accepted the authority of the Taliban leader Mullah Akhtar Mansour, in August 2015 and called on all jihadists (Islamist militant groups) to do the same.

Militant groups active in Afghanistan:

Islamic Emirate of Afghanistan: Afghan Taliban led by Mullah Akhtar Mohammad Mansour

High Council of Afghanistan Islamic Emirate: Taliban splinter group led Mullah Muhammad Rasool

Hizb-e Islami (HIG) or Islamic Party: a comparatively minor Afghan insurgent group led by Gulbuddin Hekmatyar

Tehrik-e Taliban Pakistan (TTP): Pakistani Taliban

Islamic State (IS): challenges the Taliban's legitimacy and supremacy

Al-Qaeda: supports the Afghan Taliban and has renewed its allegiance to the Taliban leader, Mullah Mansour

Lashkar-e-Taiba (LeT): Pakistani militant group traditionally focused on India

Lashkar-e-Jhangvi (LeJ): Pakistani sectarian militant group targeting Shias

Islamic Movement of Uzbekistan (IMU): linked to IS since August 2015

Islamic Jihad Union (IJU): a splinter faction of IMU now loyal to Afghan Taliban

East Turkestan Islamic Movement (ETIM): China-focused Uighur separatist group

Why Taliban special forces are fighting Islamic State

Multiple fronts

The Taliban - who remain the main insurgent group in Afghanistan - are now fighting on three fronts:

the Afghan government and its foreign allies

IS

Taliban splinter group the High Council of Afghanistan Islamic Emirate

In effect, the group has been engaged in a continuous war against the US and Nato, and Afghan forces since 2001.

It has also been fighting IS since January 2015, when IS formed its so-called Khorasan Province branch, which is active across the whole of Afghanistan plus the adjacent parts of Pakistan, Iran and Central Asian countries.

Media playback is unsupported on your device Media caption Mullah Omar dead: What we know, in one minute

The number of IS-inspired militants in Afghanistan is still low, and the group is not in a position to pose an existential threat to the Taliban in the near future, but it has created a headache nonetheless.

The third - and newest - front for the Taliban is the infighting with its own splinter group, which has diverted resources and attention.

The Taliban are very territorial and cannot tolerate the existence of other groups that challenge their supremacy and legitimacy.

In the past, they also fought against an older and comparatively minor Afghan insurgent group, Hizb-e Islami (HIG).

Splits and fragmentation

Since its launch in 1994, the Taliban have taken pride in their cohesiveness.

The group's unity and a devotional obedience to its founding leader, Mullah Mohammad Omar, played a key role in its resilience and successes on the battlefield.

But this solidarity shattered in July 2015 when Mullah Akhtar Mansour was appointed new leader in a hasty transition after Mullah Omar's death was made public.

Some of the Taliban's political leaders and military commanders challenged Mullah Mansour's right to succeed and accused him of "hijacking the movement because of personal greed".

Image copyright Getty Images Image caption Mullah Mohammad Rasool leads the Taliban splinter group

In early November 2015, a breakaway Afghan Taliban faction appointed its own leader, Mullah Mohammad Rasool (the governor of Nimroz during the Taliban regime), at a meeting of fighters in Afghanistan's western Farah province.

But the faction still hopes to reach a settlement with the main group - on the condition that Mullah Mansour is removed from leadership.

The head of the splinter group does not call himself the Amir ul-Mumineen (leader of the faithful) - the official title of the Taliban leader that makes him the political and military head and demands following his orders is a religious duty.

Soon after the splinter group was established, clashes erupted between the two sides, mainly in Zabul, Farah and Herat provinces, where the splinter group had established bases.

Fighters were killed and injured, mainly from the splinter group.

The casualties included Mansour Dadullah, the most powerful commander in the splinter group.

It is not established whether he was killed or seriously injured.

Image copyright Getty Images Image caption Zabul has become a centre of unrest

The split further entrenched when religious scholars on either side issued fatwas (Islamic religious edicts) against each other, justifying their positions on religious grounds.

At present, most Taliban leaders accept Mullah Mansour as leader.

He controls vast financial and military resources and, through recent victories on the battlefield, including the temporary capture of Kunduz in late September 2015 and the seizure of other areas in the south and north of the country, has further strengthened his position as the overall leader of insurgency.

But there are still a few Taliban heavyweights who have not publically endorsed him.

Meanwhile, both sides are lobbying to enlist the support of those prominent Taliban who have so far remained "neutral" as well as encourage others to dissent and join their ranks.

The endgame

The Taliban launched their annual spring offensive in 2015, with a clear strategy to seize more territory, establish permanent bases in "secure" areas, where the leadership can live and operate in safety, and thus strengthen their bargaining position and gain maximum advantage at the negotiation table.

It is a strategy that reflects that of IS, which has established strongholds in Raqqa in Syria and Mosul in Iraq, where the group has a governance structure and a functional administrative system.

The Taliban now hold more territory than in any year since 2001. But they could not manage to capture and hold towns and provincial capitals - an objective they had planned to achieve before this winter.

Image copyright Getty Images Image caption Afghan government forces are battling with the Taliban

And anyway the expansion of the Taliban's territorial gains doesn't automatically mean the collapse of the government in Kabul.

The stalled peace process is scheduled to restart soon. A meeting involving officials from Afghanistan, Pakistan, the US and China is due to take place in Islamabad next week to discuss the Afghan reconciliation process and draw a roadmap for talks with the Taliban.

But fighting between the Afghan government and the Taliban will probably continue, as the talks are unlikely to result in a quick political settlement.

The two sides are likely to remain in a "mutually hurting stalemate" until they reach a political settlement.

In addition to local dynamics, the war in Afghanistan has several regional and international dimensions.

There are four main parties in the Afghan peace process - the Afghan government, the Taliban, the US and Pakistan. (Many Afghan officials have long accused Pakistan of sponsoring the Afghan Taliban insurgency. Pakistan says it has contacts with the Taliban but doesn't control them).

Unless they are all on the same page and serious about reaching a political settlement, achieving a meaningful progress is unlikely.

The resolution of the problem and the ending of the conflict needs an internal consensus in Afghanistan and a multi-faceted and multinational approach involving the US and regional players.