Putting an aging parent into a nursing home and into someone else’s care is a difficult and often painful decision to make. There's the emotional toll — and also the price tag. Nursing homes, on average, cost $80,000 a year, according to a 2013 survey from Genworth USA. And prices are only going up. In fact, the cost of private nursing homes has risen 24 percent in the last five years.

Many seniors eventually bankrupt themselves to pay for it, or their children end up paying for it out of pocket. “It’s a big concern for this generation," says attorney Mark Gilfix, who specializes in estate planning and elder needs at Gilfix & La Poll Associates in California. "We call them the sandwich generation, meaning they end up paying for their parents and their own kids at the same time.” 

If it looks like your aging parents may need a nursing home, here’s how to make sure their home and other assets are protected, especially if they're middle class. “If you’re rich, then you will just pay the high costs, and if you’re poor, you won’t end up paying much. It’s the middle class that gets hurt — that’s why planning is required,” says Gilfax.

Related: How to Fall-Proof Your Aging Parent’s Home

Have “the talk” well ahead of time. It's not the easiest conversation to have with parents, but it's a necessary one, says Gilfix. "The worst thing to do is wait until a tragedy happens," says Gilfix. Sit down and talk to your parents about what assets they have. “Nobody wants to go to a nursing home. Nobody. However, it’s a reality for many people. The sooner you deal with it, the better you will be,” Gilfix says.

Plan more than five years ahead. Some people believe that right before going into a nursing home, parents can transfer assets to their children as gifts, and Medicaid will still pay for the nursing home. But this isn’t true. That money will be taken out of your Medicaid plan, and you will have to pay out of pocket. This is because of the 60-month look-back rule, under which Medicaid considers your assets over the previous five years.

“The reason why parents just can’t hand over their assets right before they enter a nursing home is that [Medicaid] sees those assets as what could have gone to funding their nursing home. Ultimately they get penalized for that,” Gilfix says. “They look back at all your assets to see how much assistance you need,” he adds.

However, parents can start giving gifts more than five years before they need to go to a nursing home. With that money, their children can create a special trust to help mom and dad.

Related: 7 Costly Money Mistakes and How to Avoid Them

Look into whether Medicaid can help with payments. Medicaid will pay for nursing homes if your parent meets the income requirements. For example, a person age 64 or older must have a monthly income less than $1,345. People who make slightly more than this also may qualify depending on their nursing home costs, but check with Medicaid about your particular circumstances. In addition, any income someone earns while in a nursing home must be paid to the nursing home. According to Gilfix, Medicaid will not pay for assisted living facilities or at-home care.

Hire an attorney. The law is complicated and varies from state to state. “You really want to talk to an attorney,” Gilfix says. “This is not something you want to screw up.”

Diane Menio, executive director of The Center for Advocacy for the Rights and Interests of the Elderly, a nonprofit based in Philadelphia, agrees. “You definitely want to consult with an attorney,” she says. “If you do it on your own, there is a high chance you will not be successful. The law is complicated. An attorney will know all the legal ways to save your assets.”

Related: Quiz: Test Your Retirement Savings Savvy