Millions of seniors rely on Medicare for health coverage during retirement. But the less you know about how that program works, the more you risk struggling to afford your healthcare costs under it.

Unfortunately, a recent Nationwide survey reveals a major knowledge gap on the Medicare front: A surprising 79% of future retirees erroneously think that Medicare Part B, which covers doctor visits and diagnostic services, is free to workers who pay Social Security taxes for at least 10 years.

Not only is Medicare Part B not free, but it's also just one of many things you'll need to pay for under Medicare. And the sooner you read up on what costs to expect, the better you'll be able to plan for them.

Eyeglasses sitting on Medicare enrollment form

IMAGE SOURCE: GETTY IMAGES.

How Medicare works

Medicare is divided into several distinct parts. Part A covers hospital care and is generally free to enrollees. That means you don't pay a premium for Part A -- but it doesn't mean you don't face expenses if you land in the hospital. Currently, you'll pay a $1,364 deductible toward your expenses under Part A before Medicare kicks in to cover the rest of your services. From there, you may be responsible for coinsurance, depending on the length of your hospital stay.

Then there's Part B, which, as mentioned earlier, covers preventive care, such as doctor visits and screening tests. Unlike Medicare Part A, Part B charges a premium, and the current standard premium is $135.50. But if you're a higher earner while on Medicare, then your premiums will be higher. For example, if you're a married couple filing jointly with an annual income of $170,000 to $214,000, your Part B premium will be $189.60.

Keep in mind that the above numbers represent 2019 figures. Medicare costs can rise over time, so use these as a benchmark only.

In addition to Parts A and B, you'll need a Part D drug plan if you want coverage for your prescriptions. The cost of your Part D premiums will depend on the plan you choose, and the cost of your copays for medication will be a function of your plan selection as well.

Now on top of the above expenses, you should know that there are certain services that Medicare won't cover, like dental care, vision exams, and hearing services. You'll therefore need to prepare to pay out of pocket for these services, unless you buy a Medicare Advantage plan. Medicare Advantage is an alternative to traditional Medicare, and in some cases, a more affordable one at that. Costs vary by plan, though, so you'll need to run the numbers to see what makes the most sense for you.

Another thing: If you stick with traditional Medicare, you may need a Medigap plan in addition. Also known as supplement insurance, Medigap will pick up the tab for certain deductible, coinsurance, and copay costs you incur under Medicare -- but you'll pay for Medigap as well.

The takeaway? Know what expenses you're signing up for with regard to Medicare, and save for them accordingly. You can do so by saving aggressively in a tax-advantaged retirement plan like an IRA or 401(k), or by funding a health savings account, which lets you set aside funds expressly for medical purposes. Not everyone is eligible to participate in a health savings account -- you'll need to be on a high-deductible health insurance plan and meet other criteria -- but if you have the option, it pays to capitalize on it. The more money you set aside prior to retirement, the easier it'll be to manage your healthcare costs when they start adding up.