Health savings accounts are among the best savings vehicles out there. Money that goes in can be deducted from federal income taxes, grows tax-free and can be withdrawn tax-free at any time if used for qualified medical expenses.

But for many retirees, one of the biggest expenses is long-term care—the ongoing need for the elderly to pay for help with the basic tasks of daily living. It’s not typically covered by medical insurance, but is it a qualified medical expense for an HSA?

The answer is yes, but there are a number of considerations to take into account to avoid taxes and penalties.

“Utilizing HSAs for LTC expenses is a planning strategy that is often overlooked by both advisors and individuals,” says Michael Berry, head of advanced planning at Voya Financial in Des Moines, Iowa. “It is essential to work with a tax advisor to determine which expenses are eligible for HSA tax-free treatment.”

Some people fund LTC expenses with LTC insurance, and the good news is that HSAs can be used to pay for LTC insurance. The bad news is there are limits. Not all LTC insurance plans are qualified, and the annual premiums are subject to age-related cutoffs. For instance, if you’re 40 or under, the maximum premium payment allowable is $410. If you’re 70 or older, it’s $5,110.

For those who don’t have LTC insurance, HSA funds can still help. “Generally speaking, LTC out-of-pocket expenses for maintenance or custodial care to assist individuals in the performance of activities of daily living may qualify,” says Jack Towarnicky, executive director of the Plan Sponsor Council of America in Westerville, Ohio.

Exactly what does and does not qualify is explained in IRS Publication 502.

“[The] definition is pretty broad,” says Dr. Katy Votava, an HSA consultant and president of GOODCARE.com in Rochester, N.Y. She adds that LTC services don’t have to be provided in an institutional setting, and that home-care services, including those that a person hires privately, can be covered with HSA dollars because those services are strictly health-maintenance related.

Steve Christenson, executive vice president of Ascensus in Brainerd, Minn., recommends documenting all expenses to help avoid subsequent headaches with the IRS.

That’s especially true if you hire a family member instead of going through a home-health agency. The HSA regulations do not specifically elaborate on whether a family member who helps you can be paid from an HSA, says Jeffrey Corliss, executive director of the RDM Financial Group at HighTower in Westport, Conn. “From our perspective, it is better to use an accredited agency, thereby removing this ambiguity,” he says.

Meanwhile, HSA-qualified LTC services must meet a “plan of care.” That’s not unlike a physician’s prescription—a document written by a licensed health-care practitioner. “[That’s] defined as any physician and any registered professional nurse, licensed social worker or other individual who meets such requirements as may be prescribed by the secretary of the Treasury,” says Harvey Cotton, a principal in the benefits consulting group of the Boston-based law firm Ropes & Gray.

Keep in mind that HSA distributions not deemed as qualified expenses will simply be taxed, and if the beneficiary is less than 65 years old, they will be subject to a 20% penalty.

“This is a very complicated area of tax law [and] the devil is in the details on a lot of this,” says Tim Steffen, director of advanced planning at Baird Private Wealth Management in Milwaukee. “The facts and circumstances of each case need to be evaluated separately.”