According to the recently released 2017 Medicare trustees' report, the Hospital Insurance trust fund, which supports taxpayer-funded Medicare Part A, ran a surplus of more than $5 billion. What's more, surpluses are expected to continue every year through 2022. However, the outlook beyond that year isn't too promising.

Here's the current state of Medicare's financial health, and what we can do to fix the program over the long run.

How Medicare funding works: The quick version

Medicare's finances are split among two trust funds. The Hospital Insurance, or HI, trust fund covers Medicare Part A, while the Supplementary Medical Insurance, or SMI, trust fund pays for Medicare Part B (medical insurance), Medicare Part D (prescription drug coverage), and administrative costs.

Pile of money with stethoscope.

Image source: Getty Images.

The HI trust fund is funded mainly through payroll taxes, specifically the Medicare portion of the payroll tax, which as of 2017 is 1.45% for both employers and employees. High-earners pay an additional 0.9% Medicare surtax as well.

On the other hand, the SMI trust fund gets its funding from the premiums paid for parts B and D coverage, as well as through funds authorized by Congress.

The good news

First, the SMI trust fund, and therefore Medicare parts B and D, are just fine. Since the trust fund is primarily financed by premiums and appropriated funds, it doesn't depend on tax revenue for its viability. Medicare premiums are reset annually, and if the higher program expenses are expected, premium income can be easily increased to meet the need.

So, when people talk about Medicare's funding issues, they're generally referring to the HI trust fund only.

Also in the good-news column: The hospital insurance program ran a $5.4 billion surplus in 2016, and is expected to run modest surpluses every year through 2022. As of the beginning of 2017, the HI trust fund had $199.1 billion in reserves.

Here's the problem

Unfortunately, that's the extent of the good news. Starting in 2023, the HI program is expected to begin running deficits, and the trust fund is expected to be completely depleted in 2029. After that point, the incoming payroll taxes will be adequate to cover only 88% of the program's promised benefits.

This is five years before Social Security is expected to run out of reserves, despite the fact that Social Security's deficits are expected to begin a year earlier than Medicare's woes, in 2022. Simply put, Social Security has a lot more in reserves. The Social Security trust fund has $2.85 trillion in reserves, which is more than triple the program's annual costs. Meanwhile, Medicare's $199.1 billion in HI reserves isn't enough to cover the program's costs for nine months. In other words, Medicare has a much-smaller cushion.

Like Social Security, the program will face a demographics-related challenge: There simply aren't going to be enough people paying into Medicare to cover its benefits for the foreseeable future. With the retirement of the massive baby boomer generation, and longer life expectancies, the number of workers paying into the system will be too low. Rising healthcare costs are expected to add to the problem.

What can we do about it?

The good news is that there is still plenty of time to fix Medicare before automatic, across-the-board cuts will become necessary. However, the sooner we devise and implement a solution, the less painful it will likely be.

For example, one possible way to fix Medicare would be to increase the Medicare portion of the payroll tax. Currently, employees pay 1.45% of their earned income to Medicare, with employers contributing an equal amount as well, for a total of 2.9%. The trustees' report projects that Medicare's 25-year deficit is equal to 0.64% of taxable payroll, which means that by increasing employees' and employers' Medicare tax by 0.32% each to 1.77% of earned income, the problem could be solved. By choosing to do this sooner, rather than later, the tax increase could potentially be phased in gradually in order to lessen its impact.

Other possible solutions include raising the age of Medicare eligibility to match the Social Security full retirement age, or allowing Medicare to negotiate drug prices in order to save money. The bottom line is that Medicare isn't viable for the long term in its current form, but it can certainly be fixed.