WASHINGTON (MarketWatch) — The nine-year-old Iraq war came to an official end on Thursday, but paying for it will continue for decades until U.S. taxpayers have shelled out an estimated $4 trillion.

Over a 50-year period, that comes to $80 billion annually.

Ceremony marks end of Iraq war

Although that only represents about 1% of nation’s gross domestic product, it’s more than half of the national budget deficit. It’s also roughly equal to what the U.S. spends on the Department of Justice, Homeland Security and the Environmental Protection Agency combined each year.

Near the start of the war, the U.S. Defense Department estimated it would cost $50 billion to $80 billion. White House economic adviser Lawrence Lindsey was dismissed in 2002 after suggesting the price of invading and occupying Iraq could reach $200 billion.

“The direct costs for the war were about $800 billion, but the indirect costs, the costs you can’t easily see, that payoff will outlast you and me,” said Lawrence Korb, a senior fellow at American Progress, a Washington, D.C. think tank, and a former assistant secretary of defense under Ronald Reagan.

Those costs include interest payments on the billions borrowed to fund the war; the cost of maintaining military bases in Kuwait, Qatar and Bahrain to defend Iraq or reoccupy the country if the Baghdad government unravels; and the expense of using private security contractors to protect U.S. property in the country and to train Iraqi forces.

Caring for veterans, more than 2 million of them, could alone reach $1 trillion, according to Paul Rieckhoff, executive director of the Iraq and Afghanistan Veterans of America, in Congressional testimony in July.

Other experts said that was too conservative and anticipate twice that amount. The advance in medical technology has helped more soldiers survive battlefield injuries, but followup care can often last a lifetime and be costly.

More than 32,000 soldiers were wounded in Iraq, according to the U.S. Department of Defense. Add in Afghanistan and that number jumps to 47,000.

Altogether, the wars in Iraq and Afghanistan could cost the U.S. between $4 trillion and $6 trillion, more than half of which would be due to the fighting in Iraq, said Neta Crawford, a political science professor at Brown University.

Her numbers, which are backed by similar studies at Columbia and Harvard universities, estimate the U.S. has already spent $2 trillion on the wars after including debt interest and the higher cost of veterans’ disabilities.

The annual budget for the Department of Veterans Affairs has more than doubled since 2003 to a requested $132.2 billion for fiscal 2012. That amount is expected to rise sharply over the next four decades as lingering health problems for veterans become more serious as they grow older.

Costs for Vietnam veterans did not peak until 30 or 40 years after the end of the war, according to Todd Harrison, a defense budget analyst with the Center for Strategic and Budgetary Assessments.

“We will have a vast overhang in domestic costs for caring for the wounded and covering retirement expenditure of the war fighters,” said Loren Thompson, a policy expert with the Lexington Institute. “The U.S. will continue to incur major costs for decades to come.”