Using 401ks
A 401k, both traditional and Roth is a good way to contribute to retirement in a tax privileged account.
However, both accounts normally can only be withdrawn from penalty free at 59 1/2.
For the traditional 401k, it’s possible to either use 72(t) SEPP (separate equal periodic payments) or a Roth conversion ladder to tap into your 401k funds before 59 1/2 and minimize fees.
With either method, you would convert money from a traditional 401k to a Roth IRA and then be able to claim your retirement funds penalty (but not income tax) free.
For a Roth 401k, however, you cannot dodge the penalty unless you’re 59 1/2. Earnings are always taxed and penalized.