The nation's largest not-for-profit hospital systems reaped more than $21 billion last year from their Wall Street investments, mergers and other investment options, according to an Axios analysis of financial documents.

Why it matters: Hospitals say they're having trouble staying afloat because insurance programs, namely Medicare and Medicaid, aren't paying them enough. But while their margins on patient care are slim, they've more than made up for it on Wall Street.

Expand chart Data: Axios review of health system financial documents; Chart: Chris Canipe and Andrew Witherspoon / Axios

The analysis: We looked at the financial documents of 84 of the biggest, most dominant not-for-profit hospital systems in the country. They don't all operate on the same fiscal year, so we looked at their latest annual filings. These systems collected $535.5 billion of annual revenue — a big piece of the entire health care system.

What we found: Cumulatively, these hospital systems made $14.4 billion in profit last year from caring for patients, for an operating profit margin of 2.7%. Add in Wall Street investments, stocks, bonds, credit default swaps and accounting gains from mergers and acquisitions, though, and their surpluses rose to $35.7 billion, or a 6.7% total profit margin — more than double the year before.

Those margins aren't gigantic. But modest margins on a large amount of revenue still equal a large amount of profit.

Many of these systems operate their own health insurance arms. Their financial status varied from extremely healthy (like Kaiser Permanente) to red ink (Partners HealthCare).

Many academic systems, including Northwestern Memorial HealthCare in Chicago and University of Colorado Health, registered some of highest margins and surpluses.

The bottom line: Top tax-exempt hospital systems are quite profitable. They are raking in cash from Wall Street, as well as from their rush to merge and acquire competing hospitals and systems. Researchers say all that consolidation often has led to higher prices and higher insurance premiums — and usually does not lower costs, contrary to hospitals' marketing pitches.

"We don't have anything close to what most people would see as a functioning, competitive market in hospital care," says Alan Sager, a health policy professor at Boston University who reviewed the analysis. "Hospitals may do well because they got dominant or because they were lucky in some of their investments."

The American Hospital Association responded to the analysis with a statement saying hospitals are benefiting from the booming stock market, and they "need a positive margin to keep pace with advances in medicine and increasing health care needs." The lobbying group also faulted Medicaid and Medicare for paying "less than the cost of care."

The AHA also said investment income gets reinvested. However, money often goes toward projects that boost revenue.

A caveat: The analysis highlights the wealthiest hospital systems in the country. But there are many hospitals — smaller, rural facilities and publicly owned hospitals — that are struggling more because of dwindling payments, fewer patients and an inability to compete against larger, better-funded systems when negotiating payment rates with commercial insurers.

"Some systems are doing really well in this country. That doesn't mean all systems and all facilities are doing well," says Gary Young, a health policy professor at Northeastern University.

Get smart: Large not-for-profit hospital systems now resemble and act like Fortune 500 companies instead of the charities they were often built as. They consequently hold immense financial and political power.