Tapping your 401(k) plan to buy a new boat is a terrible idea.

In the event of an emergency, however, your savings might be the best option available.

Workers who’ve been faithfully contributing to their workplace retirement plans likely have gathered a sizable nest egg.

The average 401(k) balance at Fidelity Investments was $106,000 at the end of the second quarter of 2019.

A handful of ambitious savers have even managed to hit seven figures: 196,000 clients of Fidelity had at least $1 million squirreled away in their 401(k).

The wisest move then is to allow your savings to compound at market returns over your working years.

However, sometimes even the most prepared individuals may experience a disaster that might require taking out a plan loan.

“One person who needed a new roof was able to get a better rate on a 401(k) loan than he could through the roofing company,” said Rockie Zeigler, a certified financial planner and founder of RP Zeigler Investment Services in Peoria, Illinois.

“I’ve never had someone come and ask me about taking a loan, but they tend to tell me after the fact,” he said.

3 ways to tap your savings

Different rules apply to withdrawals, loans and hardship distributions.

Loans. If your employer allows you to borrow from your 401(k), you may be able to take out a loan free of taxes — if you meet certain criteria.

Regardless, you’re limited to a maximum of 50% of your vested account balance or $50,000, whichever is less.

You must repay the loan within five years and make substantially level payments at least quarterly.

Withdrawals. A distribution from your 401(k) plan is subject to 20% withholding for taxes. You’re also subject to a 10% penalty if you’re under 59½.

Hardship distribution. Your plan might allow you to take a hardship distribution. The IRS allows this if it’s made due to an“immediate and heavy financial need.”

Applicable emergencies include medical care, funeral expenses and payments necessary to prevent that employee’s eviction from her home.

These distributions are included in your gross income and could be subject to additional taxes, but they aren’t repaid to the plan.

That means when you take a hardship distribution, you’ve permanently lowered your balance.

3 times when you can borrow

Cash that’s been pulled from your plan — whether withdrawn or borrowed — is no longer benefiting from compounding interest and market growth.

Your emergency fund should be the first source you hit in a crunch. The next best might be a home equity line of credit if you own a home.

If both fall short, here are three situations that may call for a 401(k) loan.

An immediate emergency: Maybe your high-deductible health care plan at work has a threshold that’s so high, you have no money in your health savings account to cover it, said Aaron Pottichen, senior vice president of Alliant Retirement Consulting in Austin.

He is referring to the tax-advantaged health savings account people can use to cover qualified medical expenses.

A cash crunch amid a bad credit period: Perhaps you need cash up front, but you don’t have the credit score to secure a personal loan at a competitive rate.

But don’t make this move without considering your ability to repay the plan loan in five years.

Costly high-interest debt is getting in the way of your long-term goals: Let’s say the interest rate on your 401(k) loan is lower than what your creditor is currently giving you.

“If you’re in ‘pay down debt mode,’ it’s all about what’s your cheapest interest rate and how fast can you get the debt down,” said Pottichen.

Want a BETTER inbox? Sign up for our newsletter to make the most of your mind, your body and your life

3 rules to follow

If you borrow from your 401(k) and fail to stick to these three rules, you’ll end up in even worse shape.

Planning on leaving? Rethink borrowing. Before the Tax Cuts and Jobs Act, workers who left their job or were laid off had 60 days to repay the loan or else face taxes.

Now you have some more time to make the payment, thanks to the tax overhaul.

If you leave your job with an unpaid loan, you may have until the due date of your federal income tax return, including extensions, to roll over the amount owed to an IRA or another 401(k) plan.

You’re still on the hook to pay what you owe. If you fail to repay it, the balance can be treated as a taxable distribution.

“Whatever loan balance remains either has to be paid off with your own money or it comes out of your 401(k) balance and is taxable,” said Zeigler. “It’s a pitfall.”

Borrow responsibly. If your finances are already dire, the last thing you want to do is load yourself with even more debt. Treat the 401(k) loan as you would any other extension of credit.

Make sure that no more than 36% of your gross monthly income is going toward servicing debt — that includes mortgage payments, credit card payments and student loan repayments.

Don’t blow off your plan’s rules. Your retirement plan will set the rules by which you can take out a loan, including the procedures for applying and the repayment terms.

The plan also spells out how your employer would handle a default, which is generally a taxable distribution. Understand the rules and stick to them.

MORE FROM BETTER

Want more tips like these? NBC News BETTER is obsessed with finding easier, healthier and smarter ways to live. Sign up for our newsletter and follow us on Facebook, Twitter and Instagram.