NEW YORK (MainStreet) — Planning for retirement is a gamble. You don't know how long you'll live, how well your investments will do or how high the cost of living will go. One of the biggest wild cards: health care costs.

The older you get, the more you're likely to spend on health care, because Medicare doesn't cover everything. So how do you plan for that?

A study by the Employee Benefit Research Institute shows that recurring health care costs for Medicare beneficiaries average $1,885 a year. If those expenses — visits to the doctor and dentist and routine prescriptions — grow at 2% a year, a person who will live to 90 will require $45,708 at 65 to pay for them.

But that's just part of the picture. Retirees also face harder-to-predict non-recurring expenses for such things as hospital and nursing home stays, outpatient surgery and home health care. For people aged 85 and over, a nursing home could cost an average of  $24,185 for two years, or $66,600 for those near the high end of the expense spectrum.

Other estimates are just as dreary. Fidelity Investments concluded a couple retiring at 65 would need $220,000 for medical expenses. And AARP, the organization for older Americans, calculated that a retiree would pay more than $3,000 a year in premiums and deductibles for Medicare Part A, B and D

So the numbers are all over the lot, but all worrisome. And what if worst comes to worst and you end up in a nursing home for longer than two years? 

The obvious solution is to have a big financial cushion. But how much are you willing to skimp on your lifestyle to prepare for a health expense you may never face?

"Rising health care expenses are forcing people to make educated decisions now more than ever, ranging from the services they utilize to the age they choose to retire," says Bradford Kimler, executive vice president of Fidelity Benefits Consulting, in a report on medical cost planning.

The first step, says Fidelity, is to assess the benefits you will have access to, and to do it before setting a retirement date. That includes deciding whether you will opt for traditional Medicare — the parts A, B and D mentioned above — or the Medicare Advantage program, which can have different costs in different parts of the country. The Medicare site has a tool for finding plans.

Also study any health care benefits your employer will provide after you retire. The more generous it is, the more it will pay to stay on the job. Unfortunately, fewer and fewer employers offer retiree health care benefits.

If you retire early, whether voluntarily or not, you cannot use Medicare before age 65, so consider other options: continuing your employer's coverage under COBRA, getting on your spouse's plan, using Obamacare or, if you qualify, veteran's benefits or Medicaid, which is for people with low income.

If your best guess about health costs in retirement is scary, an obvious though uninviting option is to postpone retirement. Staying on a workplace health insurance plan for only a couple of additional years can have a surprisingly large payoff if it reduces your out-of-pocket expenses so you can save more, gives your investments more time to grow and reduces the years you'll have to fund in retirement.

Before retiring, it's smart to build a sizable emergency fund in case sickness or an accident leaves you with unexpectedly large medical expenses. You don't want to have to sell volatile assets like stocks in a downturn.

Healthy living can reduce your risk of facing high medical expenses, so exercise, eat well and avoid tobacco.

Key to surviving a financial shock in retirement: Keep fixed costs at a minimum so you can trim expenses if necessary. That means avoiding a big mortgage or home that is expensive to maintain. That way you can spend money on other pleasures, such as travel, that can be cut in a health care crisis.

— Written by Jeff Brown for MainStreet