It's legal to borrow from your 401(k) but it isn't always possible. 401(k) loans are only an option if your company plan allows them. The Internal Revenue Service says you can spend loan money as you choose, but your plan is allowed to restrict your options.
As far as the federal government is concerned, you can take a 401(k) loan for any reason: such as to buy a house, buy a convertible, pay for tuition, pay down credit cards or eliminate other debt. However, arranging such loans is expensive for small businesses, so your employer may not offer the option. For example, some employers only allow loans to pay for education expenses, to buy a home, to avoid eviction, or to pay off medical bills.
How Big a Loan
The IRS limits how much you can borrow from your account, regardless of your plans for the money. If your account's vested balance is worth $20,000 or less, you can borrow up to $10,000, if there's that much in the account. Above $20,000, you can borrow up to half the account balance. If the balance is above $100,000, the most you can borrow is $50,000. Plans can set lower borrowing limits at their discretion. Plans can also require you borrow a minimum amount -- $1,000 is a common floor.
If your plan has restrictions, you may have to show your employer why you need the money. Otherwise, you can take it out and spend it as you choose. Your plan may allow you to take out another loan before you pay the first one back, but you won't be able to borrow as much. The plan will reduce the initial $50,000 limit using a formula based on the highest outstanding loan balance of the past 12 months and your current outstanding balance. If the plan allows you to take out a third or fourth loan, the limit will be even smaller.
Whatever reason you have for borrowing money, you have five years to repay the entire loan. The exception is that a plan can allow a longer repayment period if you're buying a house. If you leave work before you've repaid the money, the balance becomes due immediately. If you default on the loan, the IRS treats the amount you borrowed as a withdrawal. You pay income tax on the amount, and a tax penalty if you're under 59 1/2. The plan also may apply its own penalties.