Borrowing from a retirement account isn't something to do casually. Taking money out early instead of leaving it earning interest will cut into your retirement savings until you pay the loan back. If you do need the money, though, it can be cheaper to borrow from yourself than from a bank. Just consider that if the loan ends up becoming a withdrawal, you pay income tax on it, and possibly a 10-percent early-withdrawal penalty.
You can only borrow from your 401(k) if your company plan allows it. Some plans don't, and others restrict loans to specific expenses, such as tuition, high medical bills or preventing foreclosure. You can borrow up to 50 percent of the vested account balance or $50,000, whichever is less. If you leave your job, the balance of the loan usually comes due. If you can't pay within 60 days or so, the IRS will treat it as a withdrawal.
Borrowing from a Roth IRA is easy. There's no formal loan required because you can also withdraw your original contributions. To turn your withdrawal into a loan, simply put the money back in later. You don't pay a penalty or a tax on taking contributions out. You do pay if you also tap the account earnings before you turn 59 1/2, or before the account is five years old. If you roll over money into your Roth from another retirement account, you have to wait at least five years before you can withdraw it without penalty.
There's no equivalent to a 401(k) loan program for an IRA, and you can't withdraw money tax-free. If you're younger than 59 1/2, you pay income tax and penalty on what you take out, even if you put it back later. The exception is if you roll over money from one account to another. You have 60 days to complete the rollover, so you can treat the money as a short-term loan during that period. If you don't complete the transfer in time, though, the IRS will demand its cut.
Rebuilding your retirement savings after a loan can be harder than it looks. All the interest from a 401(k) goes back into the account, but many account owners find it tempting to cut back regular contributions as they're putting money in anyway. With a Roth IRA, there's no requirement to put it back if you decide not to. Even if you want to repay your Roth, you're limited to the same annual contribution limit as if you didn't withdraw money. As of 2013, that's $5,500, or $6,500 for anyone over 49.