With a 401k, the contribution cap Was 18500/year; most have the ability to do a withdrawal for the first home purchase. It does count as income when you take it out, if you write it off when it is added to the account (which is usually the case). Typically, if you are still with the employer who sponsored the 401k, you cannot make early withdrawals outside of hardship withdrawals or loans, but I have seen some companies that allow for education withdrawals.
With a Traditional IRA the cap was 5500/year, and the penalties and tax (10% & 20%) apply for withdrawals.
With a Roth IRA if it has been open for 5 years, you can withdraw the principle without penalty (since you’ve already paid tax on it when you put it in), but if you withdraw earnings you will get the same penalties and taxes as above with the Traditional IRA.
Hope this helps!