Have you ever borrowed from your employer’s retirement plan? When you need cash in a hurry, it can be tempting. After all, you don’t have to worry about a credit check and the interest just goes back into your own account.

However, there are a couple of reasons why this may not be the best idea. First, you lose any gains your money would have earned. Keep in mind that the stock market averages a 7-10% return per year, including many years with double digit returns so you could be losing out on real money.

Second, if you leave your job before paying off your loan, the outstanding balance could be considered a withdrawal and subject to taxes plus a possible 10% penalty if you’re under age 59 ½. These losses could end up jeopardizing your retirement. Here are some ways to avoid having to raid your retirement nest egg in the future:

Don’t think of your retirement account as a giant ATM. Even if your plan allows it for any reason, retirement plan loans should only be for dire emergencies and no, wanting the latest tech gadget or a vacation doesn’t qualify. Instead, calculate how much you need to save each month and have that amount automatically transferred to a separate savings account until you have enough to purchase what you want. Don’t have enough to save? Ask yourself what expenses you’re willing to cut back on to make your goal happen.

Have an emergency fund. Even if you do have an emergency, a retirement plan loan shouldn’t be your first resort. If your investments are down in value, you may not even have enough to borrow. Instead, build up enough savings to cover 3-6 months’ worth of necessary expenses and keep that money someplace safe like a savings account or money market fund. If you can’t stand the idea of all that cash just sitting there earning less than 1%, here are some ideas to put it to work harder for you.

Consider other options. For example, the average home equity interest rate is about 5%. Don’t forget that it’s tax-deductible too. If you’re in the 25% tax bracket, that loan may only cost you 3.75% after taxes, which is less than your investments will probably earn. Just be aware that your home is on the line if you can’t make the payments so this is probably not be a good idea if you’re facing severe financial hardship.

One final point is that people sometimes use a retirement plan loan to pay down credit card debt. Given how high credit card interest rates can be, this might be a smart move if it’s part of a larger plan to become free of high-interest debt. However, if you end up filing for bankruptcy, you’ll still have the retirement plan loan. In that case, you would have been better off using the bankruptcy to wipe out the credit card debt and leave your retirement account alone. (It’s generally a protected asset in bankruptcy.)

Retirement plan loans have a place, but be aware of the downsides. If you’re not sure what to do, consider consulting with a qualified financial planner. As with any financial decision, you want to make an informed one.