Yes you can borrow money from your 401k but if you borrow the money, it’s not in the account getting market gains. Assuming the market is performing well, the interest you pay on the money you loan yourself will fall WELL short of what that money would have gained through the market if it was adequately invested.