Many aspects of a particular 401k plan are governed by plan-specific rules. You should contact your plan administrator for particular rules specific to your plan.
Generally speaking, the IRS imposes a 10% penalty for withdrawals from 401k plans for taxpayers under the age of 59 1/2. However, according to the IRS, the following situations are an exception:
General exceptions: The 10% penalty does not apply to distributions that are:
1- Made as part of a series of substantially equal periodic payments (made at least annually) for your life (or life expectancy) or the joint lives (or joint life expectancies) of you and your designated beneficiary (if from a qualified retirement plan, the payments must begin after separation from service).
2- Made because you are totally and permanently disabled, or
3- Made on or after the death of the plan participant or contract holder.
4- From a qualified retirement plan (other than an IRA) after your separation from service in or after the year you reached age 55
5- From a qualified retirement plan (other than an IRA) to an alternate payee under a qualified domestic relations order,
6- From a qualified retirement plan to the extent you have deductible medical expenses (medical expenses that exceed 7.5% of your adjusted gross income), whether or not you itemize your deductions for the year,
7- From an employer plan under a written election that provides a specific schedule for distribution of your entire interest if, as of March 1, 1986, you had separated from service and had begun receiving payments under the election
8- From an employee stock ownership plan for dividends on employer securities held by the plan, or
9- From a qualified retirement plan due to an IRS levy of the plan.
(Source: IRS)