Withdrawing from a 401(k) before age 59½ has two immediate costs. The amount is added to your taxable income for the year, taxed at your marginal rate, and a 10% federal early-withdrawal penalty applies on top. Between the two, a third or more of the withdrawal commonly disappears — and state income tax, where applicable, takes more.
The larger cost is invisible: the decades of compounding you forfeit. $25,000 withdrawn at 40 isn't just $25,000 — at a 7% return it's roughly $135,000 of retirement money at 65. That's the real trade being made, and it's why cashing out is usually the most expensive way to solve a short-term cash need.