The short answer is 50% of your vested 401k balance up to $50,000 reduced by any other outstanding loans you have in the plan.
The long answer is you should only do this as a last resort for three main reasons:
1) The loan generally has to be repaid within 5 years with a few exceptions. If you fail to make payments the entire outstanding balance will be considered a distribution and you will have to pay taxes as well as a 10% penalty if you are under 59 1/2. If you leave your current employer (voluntarily or involuntarily) and there is an outstanding balance the full amount often comes due. If you are unable to pay it then it is considered a withdrawal and same taxes and penalty rules apply.
2) You will also have to pay interest as well as fees that are specific to your plan and it could make it a potentially costly option.
3) You could be missing out on returns because the payments you make usually only earn a low fixed interest rate. This could be below what you would have earned had you not taken the loan which can hurt your retirement savings in the long run.
I hope this helps