The thought of taking money out of your 401(k) retirement plan to finance an immediate need can be tempting—but it’s not so simple. You don’t want to risk your retirement plans to pay for something right now—even if it’s a house—if you can avoid doing so.

Depending on the circumstances, you might be able to take early distributions or take a loan out for yourself. However, there are risks and sometimes penalties for doing so.

What Is a 401(k)?

The 401(k) is an employer-instituted retirement plan. Employees voluntarily defer a percentage of their wages directly into their workplace’s 401(k) pension plan. Employers often match these pension contributions with contributions of their own, such as a 50-cent contribution for every dollar deposited by the employee. Some places of employment offer stock in place of monetary contributions.

All of the wage contributions and the company matches are made before taxes, which presents a tax saving for the employee. For example, if you earned $50,000 one year but contributed $3,000 to your 401(k) plan, you would declare taxable income of only $47,000.

The deferred wages earn interest that compounds over the years the pension plan is squirreled away. An employee is able to withdraw distributions from the 401(k) starting at the age of 59-½ years.

Taking Early Distributions

In certain circumstances, you can take money out early (younger than 59-½ years) from your retirement plan. Generally, this is done if you are undergoing a hardship. Keep in mind there are many variations on 401(k) retirement plans, so be sure to review your specific plan. Not all 401(k) plans are required to have a hardship distribution rule, but those that do should cover the following, according to the IRS:

  1. Medical emergencies

  2. Funeral expenses

  3. Payments related to the principal residence, including those needed to prevent eviction or to repair certain damages

Once approved by the company’s pension plan administrator, the employee can receive a substantial hardship distribution. The cost of early withdrawal is very high, though. Once withdrawn, the money is subject to all taxes and penalties and may also be liable for up to 10 percent in additional taxes.

Using a Loan From a 401(k)

In place of an early distribution, some 401(k) plans allow for employee loans. Meaning, when an employee borrows money from his 401(k), he’s borrowing money from himself and then paying the capital and interest back into his own pocket.

The good news: As long as the money is paid back, the loan isn’t taxable. Also, 401(k) loans should not affect your credit score.

The risk: If you lose or move jobs, then you’re obligated to repay the entire loan or pay full taxes and penalties as if it were an early withdrawal.

Keep in mind this will increase your debt-to-income ratio and could disqualify you for the loan or raise the cost of the mortgage. Also be aware that your lender may not let you use a 401(k) loan to buy a house. Also, while your money isn’t in the 401(k), it’s not earning interest.

Should You Take an Early Hardship Distribution From Your 401(k)?

It is probably unwise to use your retirement funds to pay for a house. Retirement money should be kept safe, so when you retire you will have sufficient income to live comfortably and cover your basic needs. But if you really do need the cash—say, you’re close to a foreclosure—taking some cash out of your 401(k) could be a viable option.

Updated from an earlier version by Dini Harris.