NEW YORK (MainStreet)—Raiding your 401(k) or IRA funds may seem like financial suicide, but in some cases it makes sense.

Some financial advisors consider it the ultimate act of financial insanity, but if you have already tapped out your emergency cash fund, borrowing from either retirement account can be a viable option.

Also see: How to Master a 401(k) and Roth IRA at the Same Time

The number of people borrowing from their 401(k) retirement accounts has increased recently, according to reports by Wells Fargo & Co. and Fidelity Investments, the largest provider of 401(k) plans.

Borrowing from your company-sponsored 401(k) plan is akin to taking out a short-term loan.

While you do not pay penalties or taxes on the income you receive from the loan, all of the loans require you to pay interest. In most cases, you are allowed to borrow half of your 401(k) balance or up to $50,000, said Andrew Valentine Pool, a portfolio manager for Regatta Research & Money Management, LLC, which is based in New Orleans.

The repayment period for the loan varies with each company, but it is generally five years or less, he said.

Also see: Your 401(k) is Invested in What?

"The majority of people borrow from their 401(k) for the wrong reasons," said Scott Sonnier, president and chief investment officer of Financial Management Services of America, based in Lafayette, La. "If there is a hardship or an emergency, then we allow for it. We don't want people accessing their money for vacation or a social function."

Most loans are paid back though payroll deductions, but many require the employee to pay an initial fee, plus interest, he said. Some loans also require an additional monthly fee.

Employers require their employees to pay the entire loan back within 30 or 60 days if they leave the position for any reason, said Pool.

"That is a big pitfall," he said.

Individuals who have not paid the loan back before they leave the company will be taxed on the remainder of the loan and pay the 10% penalty for early withdrawal, said Sonnier.

Raiding the account means employees are not taking advantage of investing their money tax-free or seeing any growth from it, Pool said.

Taking out a loan is viable only if you can pay back the amount quickly. If you need cash to pay for closing costs for refinancing a mortgage and are disciplined enough to allocate the savings for the monthly loan repayments, then it can be a good choice, he said.

The worst option is to borrow from your retirement account to purchase depreciating assets such as a car or make speculative investments such as buying individual stocks since you should have money set aside already to take that risk.

"Borrowing from your retirement in the short term is not a good idea," he said.

Tapping into your traditional or Roth IRA is another option. The IRS allows you to borrow from either type of IRA without any penalties or fees if you pay it back within 60 days once a year.

This is basically an interest free loan, but you have to be careful you replace the cash within the 60-day time period. If you miss it by even one day, you are required to pay income taxes and potentially a 10% penalty.

The most crucial element of this option is taking into account the very strict 60-day rule. Missing the deadline means you are subject to federal income taxes, the 10% penalty if you are under 59 years old and potentially even state income tax. It is best to repay the amount back a day or two early. The countdown begins the day after you receive the funds. If you are not sure you can meet this window, financial advisors suggest that you skip this option.

If you miss the deadline, the penalties and fees are stiff, depending on the tax bracket you fall within. For instance, the tax rate of a married couple whose gross income is in the $72,000 to the $146,000 range and files jointly is 25%. They must also pay the 10% penalty and pay their state income tax.

"It makes sense as a last resort," said Pool.

Also see: Your Badonk and Cancer Sticks Will Cost You Under Affordable Care

Borrowing from your 401(k) is a better option than taking a withdrawal from your IRA accounts, he said.

If you are purchasing your first home, need money to pay medical bills or funds to pay for your education, you can take a hardship withdrawal.

For your first home, you can borrow the amount of your contributions from your Roth IRA without paying penalties and taxes. The maximum amount is $10,000. If you opened the Roth IRA more than five years ago, you won't have to pay taxes. If you have owned the Roth IRA for less than five years, you only have to pay taxes on the amount.

Using a traditional IRA for a down payment is not as beneficial because you must pay taxes on all withdrawals.

There is no limit on how much you can borrow for medical expenses or higher education and there is also no time limit on the repayment period.

"These three options are manageable, because you are making an investment in yourself," said Sonnier. "However, borrowing from an IRA now will make a dramatic impact on your final value when you retire."

Utilizing your emergency cash fund remains the best option, he said.

Also see: Is ROI The Best Measure of Your College Education?

"If you have to borrow the money, because you are unemployed, then borrow only the minimum amount to pay your expenses," Sonnier said. "If you take out extra money, you will likely never pay it back. It is your money, so do everything to get educated about it. Know your choices and facts."

--Written by Ellen Chang for MainStreet