Here are the rules from the IRS website.

401(k) Resource Guide - Plan Sponsors - General Distribution Rules