More than a dozen years ago, Boeing (BA 0.25%) made a bad bet -- and it's getting worse with age.

In 2011, desperate to win contracts for a defense business that was suffering flat revenues and declining profits, and threatened by rival defense contractors trying to horn in on its aerial refueling tanker business, Boeing bid low on a contract to build new "KC-X" refueling tankers for the U.S. Air Force. For just $31.5 billion ($176 million per plane), Boeing promised to build the Air Force a fleet of 179 new tankers -- a full 10% below the bid made by rival Airbus. And Boeing won the contract.

At the time, I wrote an article warning that this might be a Pyrrhic victory for Boeing. Yes, it had won the contract, and all the revenues that came with it. But in doing so, as I noted, "Boeing also cut its profit margin to the bone."

Turns out, I was over-optimistic. Boeing cut right through its margins -- and then began sawing into the bone as well.

$7 billion in losses, and counting

Since delivering its first KC-46 refueling tanker (as the KC-X has been renamed) to the Air Force in January 2019, Boeing has racked up an astounding $7 billion in losses on the program, as Defense One reported back in April -- and it's not done yet.

To date, the Air Force has ordered 128 out of a planned 179 KC-46 tankers. Divided by $7 billion in losses, that works out to a mispricing of each plane by about $55 million. To just break even, Boeing should have charged the Air Force something closer to $230 million per plane (which is logical, because even the plain vanilla 767 airliner upon which the KC-46 is based lists for nearly $220 million).

Granted, if Boeing had told the Air Force back in 2011 that its desired 179 airplanes would cost more than $41 billion, Boeing probably would have lost the contract to Airbus (which bid $35 billion on the KC-X contract). But at least then, it would be Airbus, not Boeing, reporting losses today.

If wishes were fishes... then Boeing would lose less money

Water under the bridge, you say? Mistakes were made, but they can be rectified? Perhaps.

Boeing could make up its losses through charging for upgrades of the airplanes once they're built, and charging more for maintaining the aircraft over time. And, as the incumbent provider of Air Force tankers, Boeing will be well positioned to compete for a tanker contract the next time the Air Force needs someone to build more flying gas stations.

But in the meantime, this river keeps flowing -- and Boeing's losses keep growing.

Boeing still has 51 planes left from its original obligation to build 179 under the fixed-price contract, so it's probably going to lose at least another $2.8 billion before the contract wraps. And in fact, the next batch of losses is right around the corner.

You see, on Nov. 28, the Pentagon's daily digest of contract awards confirmed that Boeing had just "won" a contract modification instructing it to build the next 15 KC-46 tankers for the Air Force. Valued at $2.3 billion, this contract will add to Boeing's revenues -- but also to its losses.

Is Boeing stock a sell?

Speaking of which, in October's third-quarter report, Boeing reported $1.6 billion in losses on $18 billion in revenue. Granted, not all of Boeing's losses derived from the KC-46 program. But the company's defense, space, and security division, which houses not only the KC-46 program but also the company's troubled Starliner spaceship, was by far the biggest contributor to losses in the quarter, costing Boeing $924 million.

That's the bad news. Now here's the good news.

Boeing made a big mistake with the price it bid on the KC-46. But at least we can say that, with 128 out of 179 planes delivered, Boeing is seven-tenths of the way through putting its KC-46 losses in the rear-view mirror. At the same time, its commercial airplanes business is improving, with revenue up 25% year over year in Q3, and its global services business is growing both sales and earnings at healthy, high-single-digit percentage clips.

Best of all, thanks largely to the revival of its commercial business, Boeing finally looks flush with cash again. Free cash flow year to date is a respectable $4.6 billion. And according to analysts polled by S&P Global Market Intelligence, that number could grow 30% to nearly $6 billion next year.

At a market capitalization of $142 billion and a forward price-to-free-cash-flow ratio of nearly 24, I'm not ready to call Boeing stock "cheap" just yet. But at least there's a light at the end of the tunnel.