The Islamic State group’s mix of a local insurgency and digitally-connected global jihadis gives the group staying power and the means to relaunch its future, from small cells of extremists escaping the war zone in Iraq and Syria to those who never went there in the first place.

The impending loss of Mosul and Raqqa cuts out the urban heart of its self-proclaimed caliphate, but the extremist organization has built-in plans to endure and has shown a degree of flexibility that will be difficult to counteract.

For more than a year, Islamic State has acknowledged the possibility of losing the territory that propelled it to the forefront of the global jihadi movement — and drew thousands of foreign fighters. Islamic State’s goal since then has been to maintain its local and global support base in the face of overwhelming defeat. Whether it succeeds depends on what happens well after today’s battles are over.

ESCAPE CELLS

A first group of Islamic State fighters from Syria and Iraq numbering more than 100 arrived in Afghanistan at the beginning of February, followed by a smaller group, around 20, at the end of March, according to a U.N. report released last week. The group is unpopular among average Afghans, but shows traction among the young and, most importantly, receives ample funding from Islamic State’s central command to pay new fighters triple what the Taliban offers — $500 to $600 a month.

The U.N. report said Islamic State has warned its Afghanistan contingent that it will soon need to be self-financing, an ominous sign for the organization that once pulled in millions of dollars in oil money, ransoms and extortion.

Other groups of foreign fighters are feared to be trying to make their way back to Europe or North Africa, to ether plot attacks there or simply await orders.

In Europe, this has fed fears of extremists hiding among the influx of migrants, while North Africa is “really unstable. ... It’s awash in weaponry,” said Colin Clark, an analyst with the RAND think tank.

Islamic State is “a global group but it’s more regionally anchored. I don’t see them taking up and traveling wholesale to another place. They’re going to go where they have roots. They’re going to seek out these weak states. They’re going to insinuate themselves in local conflicts,” he said.

HOSTILE TAKEOVER

Al-Qaida and the Islamic State group split in 2014, driven apart less by ideology than by a dispute over timing and tactics.

Now known as Hayat Tahrir al-Sham in its latest rebranding effort, al-Qaida is on the rise in some parts of Syria and in recent days has begun targeting what it calls “organization cells” of the Islamic State group in Idlib and other Syrian provinces.

The two groups have considerable crossover — and both claim the mantle of Osama bin Laden. The al-Qaida campaign could be a precursor to demands for a merger or hostile takeover, complete with a choice of death or repentance from rank-and-file defectors.

“The differences between these groups are more in style and tone than in substance,” said Bruce Hoffman, the head of Georgetown University’s security studies program and author of “Inside Terrorism.”

Many of Islamic State’s foreign fighters, especially those from Europe, headed to Syria with the expectation of joining al-Qaida’s branch there, then switched to what they believed was the winning side. Changing back will not be very difficult, Hoffman said.

“Al-Qaida has been waiting in the wings and been letting ISIS take all the heat,” Hoffman said, using an alternative acronym for IS.

FIGHTING — OR HIDING — IN PLACE

Iraq and Syria themselves offer plenty of safe havens for local extremist fighters biding their time. At its height, IS held vast stretches of territory by promising not just brutality, but a religious government beyond corruption that would protect against arbitrary punishment, theft and graft in the service of a global movement for Sunni Muslims everywhere. The promises tapped especially into the grievances of Iraqi Sunnis, who felt abandoned by the Shiite-led government in Baghdad and were suspicious of the Kurdish government in Irbil.

Many in the U.S. have called on the Iraqi government to ensure that Sunnis share in the country’s gains going forward — a step that will prove especially complex given that Sunni areas have seen widespread destruction in the fight against the extremists. Block after block of shattered homes line the roads of Mosul, Fallujah and Ramadi.

“It’s almost at a new level of divisiveness and an unrelenting decade of bloodletting has made any sense of rebuilding a civil society unbelievably challenging,” Hoffman said. Islamic State retains a powerful presence in Iraq’s Anbar province and in the city of Tal Afar.

Islamic State’s leadership still has a core of leaders from Saddam Hussein’s Baathist organization, known for their survival skills and the support networks they built — something the group’s spokesman, Abu Muhammad Adnani, noted in a message before he was killed last summer in a U.S. airstrike: To survive “whether Allah blesses us with consolidation or we move into the bare, open desert, displaced and pursued.”

REVENGE ATTACKS

A major aspect of Islamic State’s propaganda narrative has been to offer a haven to Sunnis worldwide and until recently its videos and photos made a point of tempering extreme brutality with images of abundant harvests, children at play and efficient, free medical care.

Recently, however, its videos have depicted airstrikes destroying the caliphate, providing a powerful new message — vengeance.

Last month’s attack at London Bridge was claimed by Islamic State as revenge against the U.S.-backed coalition, and the group pledged more violence to come. With supporters from around the world linked by social media and thousands of pieces of propaganda, security officials in Europe and the U.S. fear similar attacks are in the offing.

At its height, Islamic State had tens of thousands of fighters at its disposal, though estimates varied widely. Airstrikes killed a vast percentage, the streams of Europeans heading to the war zone have dried up, and new recruits from the region are growing scarce, but its survival may not depend on numbers alone.

“The numbers may never be their 60,000 fighters or whatever, but the attraction of terrorism is the disproportionate effect a few people can have on the enemy societies and that’ll be enough to keep it alive,” Hoffman said. “The most visceral emotion we know is revenge. It is cathartic and self-satisfying and it becomes a duty.”