Before reaching retirement age, which the IRS designates as 59 1/2, you can make 401k withdrawals only in a few situations: death, in which case your beneficiary can have access to the money, as well as disability, severance from employment, the termination of the 401k plan with no successor plan in place, and a qualifying financial hardship. If you are dying, you most likely meet the definition for a qualifying disability.
A terminal illness appears to meet the stipulations for a qualifying disability in the federal tax code. Section 72(m)(7) of the code grants retirement account holders an exception to 401k withdrawal restrictions in case of a physical or mental impairment that likely will either result in death or have a long-term, debilitating effect. An account holder qualifies for the exception only upon presenting proof of the condition, such as a written diagnosis from a doctor, to the plan administrator.
Along with giving you access to your 401k funds at an earlier age than usual, a qualifying disability such as a terminal illness allows you to avoid paying the penalty for early withdrawals. In most cases, when people take 401k distributions before age 59 1/2, they must pay a 10 percent penalty on the amount of their withdrawal. But the IRS waives the penalty in some situations, including disability. You still must include your 401k withdrawal in your income for the year and pay regular federal and, if applicable, state taxes on it.
One issue to keep in mind is the option of bequeathing money in your 401k to a beneficiary or estate. The IRS allows for a distribution of your 401k funds to your beneficiary after you die at any age and waives the 10 percent penalty, although your beneficiary would have to pay taxes on the amount. If the value of your 401k is more than $3.5 million, your beneficiary would have to pay an estate tax as well based on tax rules in effect in 2011. Regardless, if you want to use part of your 401k during a terminal illness and leave part of it to a beneficiary, both arrangements are permissible and both are penalty-free.