If you want to understand what's happening in the Middle East today, you need to appreciate one fundamental fact: ISIS is losing its war for the Middle East.

This may seem hard to believe: in Iraq and Syria, the group still holds a stretch of territory larger than the United Kingdom, manned by a steady stream of foreign fighters. Fighters pledging themselves to ISIS recently executed 21 Christians in Libya.

It's certainly true that ISIS remains a terrible and urgent threat to the Middle East. The group is not on the verge of defeat, nor is its total destruction guaranteed. But, after months of ISIS expansion and victories, the group is now being beaten back. It is losing territory in the places that matter. Coalition airstrikes have hamstrung its ability to wage offensive war, and it has no friends to turn to for help. Its governance model is unsustainable and risks collapse in the long run.

Unless ISIS starts adapting, there's a very good chance its so-called caliphate is going to fall apart.

Believe it or not, Iraq is looking better than anyone could have hoped six months ago

One year ago, ISIS was soon to launch the offensive in Iraq that, in June, would sweep across northern Iraq and conquer the country's second-largest city, Mosul. Today, the Iraqi government is prepping a counter-offensive aimed at seizing Mosul back, which the US believes will launch in April.

In that year, the situation has changed dramatically. After ISIS's seemingly unstoppable rampage from June to August of 2014, the Iraqi government and its allies have turned the tide. Slowly, unevenly, but surely, ISIS is being pushed back.

"There's really nowhere where [ISIS] has momentum," Kirk Sowell, the principal at Uticensis Risk Services and an expert on Iraqi politics, told me in late January.

"There are a significant string of [Iraqi] victories all along the northern river valley, up through Diyala and Salahuddin [two central Iraqi provinces]," Doug Ollivant, National Security Council Director for Iraq from 2008-2009 and current managing partner at Mantid International, explained.

"The Islamic State ... will lose its battle to hold territory in Iraq"

In northern Iraq, Kurdish forces are threatening to cut off a highway that serves as ISIS's main supply line between Iraq and Syria. They took the town of Sinjar, which sits on the highway, in December; by late January, they had taken a longer stretch of the highway near a town called Kiske.

Ollivant describes much of the Kurdish progress in the north as a "circling around Mosul." Though the Kurds won't attempt to retake the city on their own, a joint Iraqi-Kurdish force is now poised to do so. Re-taking Mosul would be a major blow to ISIS.

To be clear, ISIS isn't on the retreat everywhere. "The news in [western province] Anbar is more mixed," Ollivant says. "Things are shifting, but not to anyone's particular advantage. The Iraqi government gains ground here, and loses ground there." In February, an ISIS offensive in Anbar threatened al-Asad airbase, where US troops are training Iraqi soldiers.

Still, ISIS is falling back in most places where it's facing a serious push. And Iraq watchers are starting to see ISIS's struggles as harbingers of a larger collapse.

"The Islamic State ... will lose its battle to hold territory in Iraq," Ollivant writes in War on the Rocks. "The outcome in Iraq is now clear to most serious analysts."

Sowell agrees. "There is no Islamic 'State' in Iraq. They're basically operating as an insurgency/mafia," he says. "They just don't have the ability, the wherewithal in Iraq to set up Sharia courts, patrol, and really govern a state."

ISIS is at a standstill in Syria

Syria is a different story. ISIS has a firm hold on the Syrian city Raqqa and its environs; it's stronger there than it is anywhere in Iraq. No faction in Syria is in a position to challenge ISIS's core holdings, at least in the near term.

Still, ISIS's months of progress in Syria have stalled. And that bodes poorly for the group's long-term prospects.

By the end of January, ISIS had been driven out of Kobane, a Kurdish town in northern Syria that it had spent enormous amounts of manpower and resources trying to seize. Kobane isn't hugely important in strategic terms. But the fact that Kurdish forces pushed ISIS back there, with support from heavy American airstrikes, does matter.

"We can take [Kobane], to a limited extent, as a signal that the airstrikes are helping roll back or at least stop [ISIS] progress in Syria," says Sasha Gordon, an associate at the private research and consulting firm Caerus Associates, who tracks developments on the ground at Syria closely.

"A lot of [elite ISIS forces] might have been lost at Kobane," adds Yasir Abbas, another Caerus associate on the Syria desk.

And ISIS has failed to make major gains outside of Kobane. "If you start with the beginning of US airstrikes in late September," Gordon says, "you'll find that ISIS hasn't taken any territory to speak of, and in fact has been rolled back in areas."

Though there have been some reports of ISIS advances in western Syria, "the territories they have gained are meaningless [or] they didn't get to keep them," Abbas explains.

"All of their major offensives since the airstrikes began — Kobane, [Deir ez-Zor] Air Base, Sha'ir Gas Field — have either been stalemates or ended in outright defeat once they squared off against Assad's troops," Daveed Gartenstein-Ross, a senior fellow at the Foundation for the Defense of Democracies, told me in late January.

Part of the reason ISIS hasn't been pushed back further is that no other faction in Syria — Bashar al-Assad's regime, al-Qaeda affiliate Jabhat al-Nusra, or the major rebel groups — have concentrated their efforts on the Islamic State.

"Everyone in Syria sees [ISIS] as a secondary priority," Gordon says, "because it's so universally unpopular that destroying it is very easy to sell and easier to do than for the regime to defeat the opposition or vice versa."

This is good and bad news for ISIS. Syria's other major groups are all focused on one another. But, at some point, that's going to change, and when it does ISIS's situation will be much more difficult.

"Do I think [ISIS] is going to be around forever? I don't think so," Gordon concludes. "But I think it can limp along so long as there's no army to take care of it."

Why ISIS is being pushed back: they're outgunned, outnumbered, and friendless

There are three simple reasons why ISIS is so weak in its supposed strongholds.

(1) Coalition airstrikes. No one expects airstrikes to collapse ISIS on their own. But they've been extraordinarily effective at blunting ISIS's ability to launch offensives in Iraq and Syria. Large masses of ISIS troops, required for such offensives, are really easy to target from the air.

"Their freedom of movement, even within their own territory [in Syria], has been significantly affected" by the strikes, Abbas says. "Before, they could send a group of elite fighters to al-Hasakah [in] the east, fight there for a couple of days, take territory then, and retreat and go and fight in Deir ez-Zor."

ISIS "relied heavily" on fast movement of elite forces for military success in both Iraq and Syria, according to Abbas. That tactic "has been taken away from them."

Moreover, US and allied air strikes have been effective at aiding ground operations against ISIS. This was most most obviously true in Kobane, where a barrage of US airstrikes was critical to the Kurdish defense's success. The strikes have also help enabled the Iraqi and Kurdish advances in Iraq.

(2) ISIS has lost the element of surprise. In conventional terms, ISIS is pretty badly outnumbered. The CIA estimates that ISIS has between 20,000 and 31,500 fighters; some private sector sources suggest that figure may be closer to 100,000. There are about 48,000 official Iraqi government soldiers, but they're buttressed by 100,000 to 120,000 Shia militiamen fighting on the government's side. The BBC reports that there are 190,000 Kurdish peshmerga in Iraq's north. And that's to say nothing of ISIS's enemies in Syria.

Now, ISIS has always been outnumbered, but had used quick surprise strikes to overwhelm its enemies. One reason ISIS managed to sweep northern Iraq last June, according to Ollivant, is that Iraqi forces were "misdeployed:" positioned in small units designed to deal with an insurgency, but vulnerable to ISIS's fast, massed vehicular assaults.

Now, American airstrikes are hampering ISIS's ability to conduct fast advances, and ISIS's enemies have redeployed. That'll allow anti-ISIS forces to leverage their superior numbers.

ISIS might be able to deal with its numbers problem if it had allies. But it doesn't, and that's the third major problem:

(3) ISIS is congenitally incapable of making allies. The group's ideology demands total and absolute adherence to its narrow and extremist interpretation of Islamic law. In their view, nobody — including al-Qaeda — is sufficiently pure. This causes ISIS fighters to lash out at people and groups who would otherwise be allies, making any alliances that ISIS forms temporary at best.

This is most pronounced in Syria: unlike Jabhat al-Nusra, the al-Qaeda franchise, ISIS has had a tough time cooperating with other rebel factions against the Assad regime, and indeed has clashed with every major faction in Syria at one point or another. In a civil war defined by the fact that no one group can overpower another, ISIS's isolation puts it at serious risk.

This is part of why ISIS "is in a much worse situation" than it was several months ago, says Joshua Landis, Director of the University of Oklahoma's Center for Middle East Studies.

"Had they just taken this large Sunni tribal region from the edge of Baghdad all the way to Aleppo, they might have been able to keep it," Landis says. "If ISIS had kept its head down, and not had such an expansive revolutionary ideology to reconquer the entire Middle East and to take on all of the crusader states, it could have been left alone by the international community."

ISIS's self-destructive ideology is its greatest weakness

ISIS has staked its entire political project on one theory: they are the true revival of the early Islamic caliphate, destined not only to maintain and expand their theocratic state but to bring on the apocalypse. Once you understand that, ISIS's blunders look less like miscalculations and more like inevitable results of its animating ideology.

"When they declared the caliphate, their legitimacy came to rest on the continuing viability of their state," Gartenstein-Ross told me in October.

More rational insurgent groups, facing a conventionally stronger foe, have a well-established playbook. Stay away from open engagements, hide among a population that's willing to shelter you, and use hit-and-run attacks to bleed the enemy to death.

The Taliban, for example, responded to the 2001 US-led invasion by giving up its state and becoming a highly durable insurgency, one that is now resurgent in Afghanistan. But ISIS so far insists on maintaining its state — even if that means fighting battles it is likely to lose against more powerful enemies. More than that, even, the group's ideology demands that it continue expanding, exposing its vulnerabilities even further.

"To be the caliph, one must meet conditions outlined in Sunni law," Graeme Wood explains in an excellent Atlantic feature on ISIS's theology. One condition is that "the caliph have territory in which he can enforce Islamic law." Once the caliphate is established, "the waging of war to expand the caliphate is an essential duty of the caliph." Everything we know about ISIS suggests its members earnestly believe this — including leader Abu Bakr al-Baghdadi.

When ISIS does something obviously shortsighted, such as deciding to invade Iraqi Kurdistan and start a losing war with the previously uninvolved Kurds, that's their ideology. They believe they need to expand territory, and that God will ensure that they do in the end.

So ISIS troops will remain out in the open, making them vulnerable to American and coalition bombs. They'll engage in conventional fights with superior enemies, because they need to keep them out of ISIS territory. And they'll continue attacking neutral parties or potential partners, because they hold territory that ISIS wants.

The deeper problems that gave rise to ISIS will be around for some time

All of these factors have put ISIS on the path to major losses, but that doesn't make the group's complete destruction inevitable, much less quick or painless. And there's no reason to believe that ISIS's defeat would solve the underlying problems that led to its rise, and will continue to plague Iraq and Syria for some time.

Even if Iraqi troops manage to topple ISIS in their country — which isn't guaranteed, and would take months or years of difficult fighting — the group's individual fighters could reform as yet another Sunni insurgency. ISIS, after all, is in many ways just one chapter in the Iraqi sectarian war that began in 2003, and it might not be the last one.

Syria is in even worse shape. Though ISIS is stalled there, it will likely have a safe haven for as long the Syrian civil war remains divided between several competing factions. Decisively addressing the factors that allowed ISIS's rise in Syria means ending both the civil war and the sectarianism that Bashar al-Assad cultivated since it began; those problems could be with us for generations.

In the short term, ISIS's setbacks in Syria have had the perverse effect of primarily benefitting not ordinary Syrians but rather al-Qaeda, ISIS's main competitor there for the mantle of Sunni extremism. As ISIS has retreated, the al-Qaeda franchise Jabhat al-Nusra has advanced, standing to gain both territory and recruits.

That even the rollback of ISIS could come with such terrible consequences is a testament to just how bad things are in Iraq and, especially, Syria. Even still, ISIS is perhaps the world's most vicious and inhumane militant group. That it is slowly losing its grip on its territory — and, with it, its ability to murder and torment the people of the Middle East — is worth appreciating.