It depends on how you measure “cost.” Does cost include just military expenses, or does it also include things like medical costs to veterans? Or lost opportunity costs?
The Washington Post pegs Iraq at at least $3 trillion.
That’s just money, of course. The most horrible cost of the war, for Americans, is the ~4,500 soldiers who died in Iraq, and the ~30,000 soldiers who were wounded, many permanently disabled. A huge proportion of veterans are also now homeless.
And even though you didn’t ask about them, the Iraqi people have paid the highest price for this war. More than 100,000 Iraqi civilians have died since the war started.
In Afghanistan about 1,500 US soldiers have died. At least 10,000 Afghan civilians have died. The official cost of the war so far is about $345 billion, but again, it depends on what else you count as “costs.”