When unexpected expenses pile up and the emergency fund runs dry, where can you turn for money during tough times? For many people, their biggest stash of savings is hidden away in tax-advantaged retirement plans, such as an IRA or 401(k).

Unfortunately, the U.S. government imposes a 10 percent penalty on any withdrawals before age 59 1/2. However, some early distributions qualify for a waiver of that penalty — for instance, certain types of hardships, higher education expenses and buying a first home.

Though the IRS does not recognize being flat broke as a hardship, there are situations when investors can tap their retirement plan before age 59 1/2 without paying the 10 percent penalty.

What is a 401(k) and IRA withdrawal penalty?

Generally, if you withdraw money from a 401(k) before the plan’s normal retirement age or from an IRA before turning 59 ½, you’ll pay an additional 10 percent in income tax as a penalty. But there are some exceptions that allow for penalty-free withdrawals.

Penalty-free does not mean tax-free

Some hardship situations qualify for a penalty exemption from an IRA or a 401(k) plan, but note that penalty-free does not mean tax-free:

  • Withdrawals from traditional IRA and 401(k) plans made with pre-tax contributions are taxed at ordinary income rates.
  • Withdrawals of nondeductible contributions (i.e., those made after-tax) to traditional IRA and 401(k) plans are not subject to the same taxes as deductible contributions, though workers will still incur taxes on any earnings that have been withdrawn from the accounts.
  • Contributions to a Roth IRA can be taken out at any time, and after the account holder turns age 59 ½ the earnings may be withdrawn penalty-free and tax-free as long as the account has been open for at least five years. The same rules apply to a Roth 401(k), but only if the employer’s plan permits.

In certain situations, a traditional IRA offers penalty-free withdrawals even when an employer-sponsored plan does not. We explain those situations below. Also, be aware that employer plans don’t have to provide for hardship withdrawals at all. Many do, but they may permit hardship withdrawals only in certain situations — for instance, for medical or funeral expenses, but not for housing or education purposes.

Here are the ways to take penalty-free withdrawals from your IRA or 401(k)

1. Unreimbursed medical bills

The government will allow investors to withdraw money from their qualified retirement plan to pay for unreimbursed deductible medical expenses that exceed 10 percent of adjusted gross income.

The withdrawal must be made in the same year that the medical bills were incurred, says Alan Rothstein, a CPA at Rothstein & Co., in Avon, Connecticut.

You do not have to itemize deductions to take advantage of this exception to the 10 percent tax penalty, according to IRS Publication 590.

2. Disability

The IRS dictates that investors must be totally and permanently disabled before they can dip into their retirement plans without paying a 10 percent penalty.

Rothstein says the easiest way to prove disability to the IRS is by collecting disability payments from an insurance company or from Social Security.

3. Health insurance premiums

Penalty-free withdrawals can be taken from an IRA if you’re unemployed and the money is used to pay health insurance premiums. The caveat is that you must be unemployed for 12 weeks.

To leave a clean trail just in case of an audit, Rothstein suggests opening a separate bank account to receive transfers from the IRA and then using it to pay the premiums only.

“Or the best way is to have the money sent to the insurance carrier directly,” he says.

4. Death

When an IRA account holder dies, the beneficiaries can take withdrawals from the account without paying the 10 percent penalty. However, the IRS imposes restrictions on spouses who inherit an IRA and elect to treat it as their own. They may be subject to the penalty if they take a distribution before age 59 1/2.

5. If you owe the IRS

If Uncle Sam comes after your IRA for unpaid taxes, or in other words, places a levy against the account, you can take a penalty-free withdrawal, says Joe Gordon, a CFP and co-founder of Gordon Asset Management in Durham, North Carolina.

6. First-time homebuyers

Though you may take money out of your 401(k) to use as a down payment, expect to pay a 10 percent penalty.

However, take the money from your IRA, and it’s penalty-free. The penalty-free withdrawal is not limited to first-timers either. Homebuyers must not have owned a home in the previous two years, though. Further, you can take more than one penalty-free withdrawal to buy a home, but there is a $10,000 limit.

For example, says Rothstein, “You can do two $5,000 withdrawals, but $10,000 is the lifetime limit.”

Taking money out of a 401(k) for a down payment can be trickier.

“When the 401(k) has both a loan provision and hardship withdrawal provision, the participant must first use the loan provision before going to hardship,” Gordon says.

7. Higher education expenses

Similarly, withdrawals can generally be made from a 401(k) to cover higher education expenses if the plan allows hardship withdrawals, but they will be subject to the 10 percent penalty.

However, IRA withdrawals are penalty-free if used to pay for qualified expenses.

“It can be for yourself, your spouse, children, grandchildren, or immediate family members. Typically, it will cover books, tuition, supplies, room and board and for postsecondary education,” says Bonnie Kirchner, a CFP and author of “Who Can You Trust With Your Money?”

8. For income purposes

Section 72(t) of the tax code allows investors to take money out of their retirement plan for income, but there are restrictions.

“You’ll have to take substantially equal periodic payments” over time, Kirchner says.

The shortest amount of time that payments must be made is five years. One option is taking a distribution annually for five years or until age 59 1/2, whichever is longer.

For example, early retirees may want to tap their retirement accounts before Social Security kicks in.

“The gist is that you take the payments and you pay the taxes, but you pay no penalty even if you’re 52 or 53 years old,” Gordon says.

There are other options for the distributions that allow an investor to take payments “over their life expectancy or do a reverse-mortgage-type amortization,” Gordon says.

These periodic payments can also be spread over the course of your life and that of your designated beneficiary.

How to avoid early withdrawals

Tapping your retirement savings should only be used as a last resort. Here are some ways to avoid accessing your 401(k) or IRA early:

Build an emergency fund

This should be the foundation of your financial plan and financial advisors recommend having about six months’ worth of expenses saved. You can park this money in a high-yield savings account to earn more interest than you would in a traditional checking account. An emergency fund should help you manage most of life’s curveballs.

Take advantage of promotional credit card offers

Consider utilizing an introductory credit card offering that includes zero percent interest for a period of time. This could help you finance your spending needs immediately, but be careful not to let the balance carry over once the higher interest rate kicks in.

Try to get help from friends and family

Relying on your community for financial support during tough times can be a great way to make ends meet without going into debt or tapping retirement accounts.

Friends and family are often more forgiving than a financial institution might be with a loan.

Take out a personal loan

There’s also the option of taking out a personal loan to help deal with a temporary setback. Personal loans aren’t backed by any assets, which means lenders won’t easily be able to take your house or car in the event you don’t pay back the loan. But because personal loans are unsecured, they can be more difficult to get and the amount you can borrow will depend on variables such as your credit score and your income level.

If you think a personal loan is your best option, it may be a good idea to apply for one with a bank or credit union where you have an existing account. You’re more likely to get the loan from an institution that knows you and they might even give you some flexibility in the event you miss a payment.

Use a portfolio line of credit

You could also consider taking out a portfolio line of credit, which is essentially a loan backed by securities held in your portfolio, such as stocks or bonds. Interest rates on a portfolio line of credit tend to be lower than that of traditional loans or credit cards because they’re backed by collateral that the lender will receive in the event you can’t pay back the loan.

However, if the value of your collateral falls, the lender can require you to put up additional securities. The lender could also become concerned with the securities being used as collateral. Government bonds will be viewed as much safer collateral than a high-flying tech stock.

Bottom line

In most circumstances, taking an early withdrawal from your 401(k) or IRA will result in an additional 10 percent penalty on top of income taxes. There are instances where the penalty is waived, but you’ll still pay regular income tax on the withdrawal. Try to avoid making withdrawals if possible and be sure to have a strong emergency fund built up for tough times.