Although the wars in Afghanistan and Iraq are far from the costliest the United States has ever fought in terms of either blood or treasure, they have exacted a much greater toll than the relatively bloodless wars Americans had gotten used to fighting in the 1990s. As of this writing, 2,344 U.S. troops have been killed in Afghanistan and 4,486 in Iraq, and tens of thousands more have been injured. The financial costs reach into the trillions of dollars.

Yet despite this investment, the returns look meager. Sunni extremists from the Islamic State of Iraq and al-Sham (ISIS), also known as the Islamic State, and Shiite extremists beholden to Iran have divided the non-Kurdish parts of Iraq between them. Meanwhile, the Taliban and the Haqqani network remain on the offensive in Afghanistan. Given how poorly things have turned out, it would be tempting to conclude that the United States should simply swear off such irregular conflicts for good.

If only a nation as powerful and vulnerable as the United States had the option of defining exactly which types of wars it wages. Reality, alas, seldom cooperates. Over the centuries, U.S. presidents of all political persuasions have found it necessary to send troops to fight adversaries ranging from the Barbary pirates to Filipino insurrectos to Haitian cacos to Vietnamese communists to Somali warlords to Serbian death squads to Taliban guerrillas to al Qaeda terrorists. Unlike traditional armies, these enemies seldom met U.S. forces in the open, which meant that they could not be defeated quickly. To beat such shadowy foes, American troops had to undertake the time-intensive, difficult work of what’s now known as counterinsurgency, counterterrorism, and nation building.

There is little reason to think the future will prove any different, since conflict within states continues to break out far more frequently than conflict among states. Although the world has not seen a purely conventional war since the Russian invasion of Georgia in 2008, more than 30 countries -- including Colombia, Iraq, Israel, Mexico, Nigeria, Pakistan, Somalia, and Ukraine, to name a few -- now find themselves fighting foes that rely on guerrilla or terrorist tactics. One such conflict, the civil war in Syria, has killed over 170,000 people since 2011. Given how many of these conflicts involve U.S. allies or interests, it is wishful thinking to imagine that Washington can stay aloof. Indeed, President Barack Obama himself, who campaigned against the war in Iraq, has been compelled to fight again there because of the threat from ISIS.

Even if the United States does not send substantial numbers of ground troops to another war anytime soon, it will surely remain involved in helping its allies fight conflicts similar to those in Afghanistan and Iraq, and as has become clear in recent months, it will stay involved in Afghanistan and Iraq, too. Since Washington doesn’t have the luxury of simply avoiding insurgencies, then, the best strategy would be to fight them better. Drawn from more than a decade of war, here are ten lessons for how to do so, which U.S. policymakers, soldiers, diplomats, and spies should keep in mind as they try to deal with the chaotic conflicts to come.

THE BEST-LAID PLANS

The first lesson may sound like a no-brainer, but it has been routinely ignored: plan for what comes after the overthrow of a regime. In Afghanistan and Iraq, the George W. Bush administration failed to adequately prepare for what the military calls “Phase IV,” the period after immediate victory -- an oversight that allowed law and order to break down in both countries and insurgencies to metastasize. Yet Obama, despite his criticism of Bush’s conduct of the Iraq war, repeated the same mistake in Libya. In 2011, U.S. and nato forces helped rebels topple Muammar al-Qaddafi but then did very little to help the nascent Libyan government establish control of its own territory. As a result, Libya remains riven by militias, which have plunged the country into chaos. Just this past July -- almost two years after U.S. Ambassador Christopher Stevens was killed in Benghazi -- the State Department had to evacuate its entire embassy staff from Tripoli after fighting there reached the airport.

This is not a problem confined to Bush or Obama. The United States has a long tradition of bungling the conclusions to wars, focusing on narrow military objectives while ignoring the political end state that troops are supposed to be fighting for. This inattention made possible the persecution of freed slaves and their white champions in the South after the American Civil War, the eruption of the Philippine insurrection after the Spanish-American War, the rise of the Nazis in Germany and the Communists in Russia after World War I, the invasions of South Korea and South Vietnam after World War II, and the impetus for the Iraq war after the Gulf War. Too often, U.S. officials have assumed that all the United States has to do is get rid of the bad guys and the postwar peace will take care of itself. But it simply isn’t so. Generating order out of chaos is one of the hardest tasks any country can attempt, and it requires considerable preparation of the kind that the U.S. military undertook for the occupation of Germany and Japan after 1945 -- but seldom did before and has seldom done since.

THINK AGAIN

An equally important lesson is to challenge rosy assumptions during the course of a conflict. Following the overthrow of Saddam Hussein, the Bush administration opted for the smallest possible footprint in Iraq. The faster U.S. forces pulled out and the more elections Iraqis held, they reasoned, the more likely Iraqis would be to take responsibility for their own problems. This strategy was plausible -- and wrong. By the end of 2005, at the latest, Bush; his secretary of defense, Donald Rumsfeld; and the commander of coalition forces in Iraq, General George Casey, should have known that their strategy was failing. Yet Bush did not reevaluate it until the end of 2006, at the 11th hour, when defeat was imminent. Rumsfeld and Casey never seemed to reevaluate it at all.

The same pathology afflicted U.S. division, brigade, and battalion commanders, who always seemed convinced that they were making progress in their areas of operations. On regular visits to Iraq from 2003 on, I never heard someone giving a brief say the situation was getting worse; commanders invariably painted a picture of challenges that were being overcome. (The usual subtext: “The previous unit in this area really screwed things up, but we’ve got it headed in the right direction.”) It’s not as if alternative assessments were hard to come by: all you had to do was pick up The New York Times or The Washington Post to find out that Iraq was degenerating into civil war. Many lower-level soldiers even admitted as much privately. But those higher up in the chain of command dismissed bad news as mere data points that failed to capture the hidden progress Iraq was supposedly making.

The Bush administration’s political commitment to the Iraq war was partly to blame, since it blinded decision-makers to evidence that their initiatives were failing. Likewise, generals developed an emotional attachment to the strategies they implemented. The Pentagon’s can-do culture also got in the way. The U.S. military’s greatest virtues -- its commitment to following orders, its unwillingness to accept excuses for failure, its insistence on achieving objectives no matter the obstacles -- are also its greatest vulnerabilities. They can make it hard for junior soldiers to tell their superiors uncomfortable truths (or even to think such dangerous thoughts).

The success of the “surge” in Iraq started with the willingness of General David Petraeus, who was named commander of coalition forces in Iraq in early 2007, to acknowledge that the war was in danger of being lost. With an additional 30,000 troops, he put in place a new, and ultimately more successful, strategy that focused on protecting the population. To get an accurate picture of events on the ground, Petraeus bypassed the chain of command and sought information directly from junior soldiers and civilian experts, including reporters and think tankers. The military needs to institutionalize a similar culture of second-guessing (or “red teaming”) and regularly seek outside information in order to escape the tyranny of yes men in the chain of command.

STRATEGIC STAFFING

The United States also needs to cultivate better strategic thinkers in both the military and the civilian spheres. The country’s best and brightest made mistakes in Afghanistan and Iraq that were just as monumental as the ones famously made by their predecessors in Vietnam. A decade of war exposed the flaws of experienced, highly credentialed civilians, such as Vice President Dick Cheney, Rumsfeld, Paul Bremer (the head of the Coalition Provisional Authority in Iraq), and Richard Holbrooke (the special envoy to Afghanistan and Pakistan); of equally experienced and equally credentialed military officers, such as Casey, Tommy Franks, Ricardo Sanchez, John Abizaid, and David McKiernan; and of a few officers turned senior civilians, such as Karl Eikenberry (the U.S. ambassador to Afghanistan).

Petraeus and Ryan Crocker, the U.S. ambassador to Iraq who led the civilian side of the surge in 2007–8, represent two of the very few senior officials to emerge from the wars with their reputations improved. That’s because they exhibited a rare quality in the U.S. military: strategic acumen. Not even General Stanley McChrystal, who achieved legendary status for his success in running the Joint Special Operations Command, was able to make the transition to a theater-level commander in Afghanistan; he was forced to resign in 2010 after his staff made impolitic comments to a Rolling Stone reporter.

It’s no coincidence that Petraeus and Crocker also had unusual backgrounds. Unlike most generals, Petraeus did not attend a war college for midcareer studies; he got a Ph.D. in international relations from Princeton instead. Crocker, too, did graduate studies at Princeton. He also spent time as a truck driver, a construction worker, a bartender, a cabby, and a waiter, and he once hitchhiked from Amsterdam to Calcutta. “It nearly killed me but gave me a view of the region that no diplomat will ever get,” he told me. Obviously, the Pentagon cannot mandate that all its future leaders spend time driving taxis, attend Ivy League schools, or travel across Eurasia. But it should encourage up-and-comers to pursue diverse experiences rather than follow a well-trodden path. And it should abandon its practice of promoting officers on the basis of their operational excellence alone and also consider their strategic intelligence.

TRAINING DAY

Another lesson the Pentagon should take to heart is the importance of training for more than just short conventional operations. The U.S. government ran into trouble in Afghanistan and Iraq in large part because it simply was not set up to do nation building and counterinsurgency. When it became clear after Saddam’s downfall in April 2003 that Iraq wouldn’t automatically govern itself, the job was given first to the Office of Reconstruction and Humanitarian Assistance and then to the Coalition Provisional Authority -- both ludicrously ill prepared for the monumental challenges they faced. Whereas military units train for years to take down regimes like Saddam’s, their civilian counterparts had at most a few weeks to prepare for the much more difficult task of governing a foreign land.

The situation wasn’t much better in Afghanistan. Although a provisional government formed within just weeks after the Taliban’s downfall, it enjoyed tenuous authority. President Hamid Karzai was in practice little more than the mayor of Kabul, yet the Bush administration and the U.S. military did not consider it their job to extend his authority. The result was a power vacuum, which was filled by corrupt warlords and a resurgent Taliban. In both Afghanistan and Iraq, the U.S. military’s narrow focus on hunting down insurgents, rather than denying them a raison d’être, engendered more support for them because it resulted in the imprisonment or death of so many innocent individuals.

Through trial and error, the U.S. military learned to wage counterinsurgency and build functional states rather than simply conduct firepower-intensive operations. Yet there is a real danger it could lose that expertise as it lays off veterans due to budget cuts and returns to its real passion: preparing for conventional wars that never quite arrive. It is not comforting to learn, for example, that in October, the army shuttered the Army Irregular Warfare Center at Fort Leavenworth, Kansas, which was set up in 2006 to reintroduce counterinsurgency into military thinking. Counterinsurgency needs to remain part of the military curriculum, and the Pentagon needs to issue a manual and inaugurate a school dedicated to governance. (A new institute devoted to the subject is just now being developed at the U.S. Army John F. Kennedy Special Warfare Center and School, at Fort Bragg, North Carolina; a full-fledged school should have opened long ago.)

The civilian side is in even worse shape. For all the talk of a “civilian surge” in Afghanistan and Iraq, the State Department and other government agencies could never provide enough skilled personnel in such areas as governance and economic development to complement the military’s efforts; soldiers wound up filling many of the jobs. The problem is that no agency within the U.S. government views nation building as its assignment. The closest any comes is the U.S. Agency for International Development, but it has a nebulous mission and scant resources of its own. It is high time to revamp USAID, making it into an organization focused not on development for its own sake but on state building in countries of strategic concern, from Mali to Pakistan. As part of this shift, USAID should hire some of the soldiers the U.S. Army and the Marine Corps are laying off who have considerable expertise in nation building.

SPEAKING IN TONGUES

Preparing for nation building also requires the U.S. government to boost its cultural and linguistic skills. The biggest vulnerability for U.S. forces in Afghanistan and Iraq was their lack of local knowledge, a problem made clear by an experience I had in an area southwest of Baghdad in August 2003. I was traveling with a group of marines when an improvised explosive device blew up near our convoy. While the marines searched for the culprit, an Iraqi man approached us and tried to tell us something, but he spoke no English and we spoke no Arabic. The military partially rectified this problem by hiring many interpreters and so-called cultural advisers, who could communicate with the people of Afghanistan and Iraq.

But those countries represent only two battlefields of many in the broader struggle against Islamist extremism. Today, the U.S. government is as deficient in cultural and linguistic knowledge about Iran, Libya, Mali, Nigeria, Pakistan, and Syria as it once was about Afghanistan and Iraq. The United States simply doesn’t have many soldiers, diplomats, or intelligence officers who are fluent in such languages as Arabic, Farsi, Pashto, and Urdu, to say nothing of the local dialects spoken throughout much of Africa and South Asia. And it’s not just a question of knowing foreign languages; even more important in many ways is a country’s power structures, customs, and mindsets.

The U.S. Army’s decision in 2012 to create regionally aligned brigades, each one focused on a particular part of the world, counts as a small step in the right direction, but it’s doubtful that most troops will have much time or energy to devote to cultural and language studies, given the countless other tasks they must perform. To make matters worse, the army’s policy of nonstop rotations means that soldiers rarely stay in one unit or one region long enough to acquire true expertise.

The military does already have a corps of foreign area officers, who have regional expertise, but they rarely secure important command assignments. The Pentagon needs to mainstream these officers by giving them more credit for their expertise in the promotion and assignment process, and it should permit some of them to stay in hot spots for years, even decades, giving them a chance to gain knowledge and influence. Some of these volunteers should be foreign-born; the Pentagon needs to expand its Military Accessions Vital to the National Interest, or MAVNI, program, which allows immigrants who don’t have green cards but do have needed skills to enlist. This initiative has brought in highly qualified soldiers, including Sergeant Saral Shrestha, a Nepalese immigrant whom the army named Soldier of the Year in 2012. But with just 1,500 slots a year (many of which are reserved for technical positions), MAVNI is far too small. The Pentagon should also create an organization dedicated to advising foreign counterparts -- arguably the most important mission in the years ahead, but one that today often gets relegated to the lowest-rated officers who have been pulled out of regular combat formations.

THE RIFLEMAN ON THE CORNER

When facing future counterinsurgencies, the U.S. military also needs to learn that it cannot rely too much on high-tech firepower and special operations forces. Afghanistan and Iraq laid bare the shortcomings of precision bombing, drone strikes, and commando raids. In Iraq, all these capabilities proved important, but none was sufficient to turn the tide; the situation didn’t begin to improve until the U.S. military adopted a population-centric strategy in 2007. The same was true in Afghanistan, where it did not implement a counterinsurgency strategy until 2010. Before then, special operations raids had no lasting impact; new insurgents quickly replaced those captured or killed. Only after U.S. and Afghan forces entered the provinces of Helmand and Kandahar in massive numbers could they secure districts the Taliban had long controlled.

When it comes to enforcing regime change, there is still no replacement for a rifleman on a street corner. Drone strikes and raids can eliminate terrorist leaders, but they cannot uproot entire terrorist organizations. That requires controlling enough terrain to prevent insurgent organizations from regenerating themselves in the way that al Qaeda, Hamas, Hezbollah, ISIS, and the Pakistani Taliban, among others, have after the loss of their leaders.

Yet the U.S. government is once again cutting ground forces and becoming overly reliant on drone strikes and special operations forces. In essence, policymakers are repeating the mistake Rumsfeld made before 9/11, when he openly contemplated cutting two divisions from the army -- only now, they are slashing even more combat power. Congress needs to reverse the destructive decline in the number of active-duty soldiers, which, if the most drastic budget cuts take effect, could fall from a peak of 570,000 in 2011 to as few as 420,000 over the next decade.

In the past decade, even 570,000 troops proved insufficient for coping with two limited conflicts against relatively primitive foes who lacked the high-tech weapons that future adversaries will likely wield. Were the number to drop to 420,000, the army would have trouble fighting even one ground war, given that less than one-third of all troops can be sent to battle at any given time (most of the others are either recovering from deployment or preparing for it). Fighting two wars at a time -- once the gold standard of U.S. military strategy -- would be utterly impossible. Those who think the United States will never fight another ground war should remember that many people thought the same after World War I -- and then after World War II, the Korean War, the Vietnam War, and the Gulf War.

BASING INSTINCT

The next lesson may seem to get into the weeds but in fact has high-level ramifications: don’t let logistics drive strategy. The U.S. military created a massive logistical footprint in Afghanistan and Iraq, erecting a series of heavily fortified Little Americas that offered troops everything from ice cream to large-screen TVs. These compounds proved staggeringly expensive to resupply. In the summer of 2006, when both conflicts were going strong, U.S. Central Command had more than 3,000 trucks delivering supplies and another 2,400 delivering fuel to its bases, and these convoys had to be protected by either troops or contractors. The military thus became what soldiers sometimes called a “self-licking ice cream cone” -- an organization that fought to sustain itself rather than to achieve a mission.

It is doubtful that senior commanders ever gave much thought to these logistical requirements; they more or less operated on autopilot. Each base commander would bring in a few more amenities to make life better for the troops, a commendable impulse. But in the process, commanders not only created supply-line vulnerabilities but also cut off troops from the populace, neglecting an essential part of any successful counterinsurgency campaign. In the future, the Pentagon should resist the temptation to build up huge bases unless doing so accomplishes the objectives of the war.

MANAGING MERCENARIES

Another specific yet vital lesson is that the U.S. government needs to exercise greater authority over contractors on the battlefield. After its post–Cold War downsizing, the military lacked enough troops to control both Afghanistan and Iraq. So the Pentagon relied heavily on contractors for everything from doing laundry at bases to protecting convoys. Although most were not armed, a significant minority were (16 percent of those in Afghanistan at the end of 2013), and they generated numerous complaints about their alleged abuses. Driving armored black SUVs, contractors frequently careened through towns in Afghanistan and Iraq, forcing civilian cars off the road and sometimes shooting at vehicles that got too close. The most notorious offender was Blackwater, whose employees killed 17 people in Baghdad’s Nisour Square in 2007.

Although security contractors usually got the job done, sometimes heroically, the way their job was defined was itself a problem. The U.S. government hired them to move goods or people from Point A to Point B, no matter the consequences. Unlike troops, who were told to win hearts and minds, contractors had virtual carte blanche to achieve their narrow objectives. They were effectively exempt from prosecution under the Uniform Code of Military Justice and even from lesser forms of discipline.

The inevitable result of setting loose all these armed, aggressive men was a series of abuses that harmed U.S. relations with the locals. Both Karzai and Iraqi Prime Minister Nouri al-Maliki grew exercised about the contractors’ behavior over time and threatened to kick them out. Congress reacted in 2004 by amending U.S. law to allow the prosecution of U.S. contractors by U.S. courts. So far, however, only 12 people have been charged under these statutes, including six Blackwater guards implicated in the Nisour Square shooting. One pled guilty, another had the charges against him dropped, and the remaining four went on trial in federal court in Washington, D.C., in the summer of 2014 -- a scandalous six years after their indictment.

Continued downsizing will mean that the military won’t be able to stop relying on contractors in future conflicts. But it can control them better. One possible model is the way that U.S. commanders exercise authority over foreign troops. Just as the troops from contributing nations plug into a U.S.-led command structure, contractors could, too. In the future, the U.S. government should write its contracts differently. Security firms working for any branch of the U.S. government, including the State Department and USAID, and operating on a battlefield where the U.S. military is present should fall under the operational control of a senior U.S. military officer who has the power to revoke their contracts and prosecute their employees in case of misdeeds.

PLAYING NICE TOGETHER

Another lesson involves what the military calls “interoperability,” the ability of various components to work together smoothly. One of the U.S. government’s biggest successes in Afghanistan and Iraq was the improvements it made in getting U.S. forces to cooperate with foreign forces and getting different types of U.S. forces to cooperate with one another.

In particular, special operations and regular forces learned to work hand in hand after years of mutual resentment. During the Gulf War, General Norman Schwarzkopf looked at special operations forces with so much suspicion that he tried to keep them off the battlefield altogether. In the early years of Afghanistan and Iraq, many conventional commanders also complained about special operations forces entering their areas without permission and undertaking operations (such as a raid on an influential sheik) without considering how such actions might destroy carefully nurtured relationships.

Those problems never entirely went away, but by 2007, special operations forces (in particular, the elite members of the Joint Special Operations Command) came to occupy a central place in U.S. strategy in Afghanistan and Iraq, and their dealings with regular troops became far more harmonious. Relations between U.S. forces and allied ones also improved, even if Australia, Canada, and the United Kingdom continued to complain about Washington’s proclivity to deny them the most sensitive intelligence -- yet another area where there is room for improvement.

Some U.S. military commanders developed close relationships with their civilian advisers, but just as often, the relationships were antagonistic and dysfunctional. In the future, the conventional military and its civilian, foreign, and special operations counterparts must train together, which should help smooth their relations in the field.

THE LONG HAUL

Finally, Washington must recognize that counterinsurgency and nation building take time. In Iraq, the United States had all but won by 2011, when U.S. troops had to leave because Obama failed to negotiate a new status-of-forces agreement, in part because he never made it a priority. Now, ISIS has gained control of a chunk of Syria and Iraq larger than the United Kingdom and declared a caliphate, and violence in Iraq has shot back to its 2008 level. A similar disaster could occur in Afghanistan if the United States pulls out completely in 2016, as Obama has pledged. In any given conflict, Washington needs to make a long-term commitment, as in Kosovo, where U.S. troops have been deployed since 1999. Otherwise, it shouldn’t bother to get involved in the first place.

Skeptics argue that a fickle American public will never support long-term deployments of U.S. soldiers, and so serious counterinsurgency campaigns are a nonstarter. In fact, Americans have shown impressive patience with the wars in Afghanistan and Iraq, which explains why the United States has remained involved in those conflicts far longer than anyone initially imagined possible. The public may not be enthusiastic about these campaigns, but neither has the country seen protests of the scale it did during the Vietnam War.

The only time when either of the two recent wars became a major political issue was in 2006 and 2007, when U.S. fatalities in Iraq reached over 100 a month and the war looked lost. The one thing that the U.S. public won’t tolerate is making sacrifices for a losing cause. But after the success of the surge, public opposition waned. Had Obama struck a status-of-forces agreement with Iraq in 2011, he would have faced no serious political obstacle to keeping thousands of troops there. Likewise, no political obstacle prevents him from keeping thousands of troops in Afghanistan past 2014, or even past 2016.

Some of these recommendations call for little more than new policies; others entail major changes in the institutional culture of the military and the broader U.S. government. None will be easy to implement; there will be fierce opposition on Capitol Hill to boosting defense spending or creating a nation-building agency, for example, and fierce opposition in the Pentagon to revising the military’s personnel system or emphasizing culture and language as much as traditional war-fighting skills. And even if policymakers take all these lessons to heart, they can hardly guarantee success in undertakings as grueling and complicated as counterinsurgency and nation building. But refusing to heed these lessons practically guarantees that the United States’ future wars will, at best, succeed at a much higher cost than necessary -- and, at worse, fail outright.