Unlike a taxable brokerage account, when you sell stock in a retirement account like a 401(k), you don't have to pay taxes on it if you reinvest that money. Additionally, the money you invest in a retirement account is tax-deductible. That means you don't pay taxes on that income until you withdraw from the account in retirement, at which point the money will have hopefully appreciated significantly.
Other tax-deferred employer-sponsored retirement plans include the 457 and the 403(b). Another popular tax-deferred retirement account is the individual retirement account (IRA), which is open to anyone regardless of employment status.
A traditional IRA works similarly to a 401(k). You contribute pre-tax income up to a set limit, which can grow without capital gains taxes until you withdraw from it, and it's treated like ordinary income.
There's also the Roth IRA, which does not offer a tax benefit when you contribute to it, but withdrawals are tax-free, making it a different way to take advantage of tax-deferred growth. Effectively, a Roth IRA gives you tax-free growth once you contribute to it.
Other ways to benefit from tax-deferred growth
If you're investing in a traditional taxable account, the laws of compounding and tax deferment incentivize you to buy and hold stocks rather than trade them frequently. While you'll still have to pay capital gains tax on those investments, you'll pay less than you would by selling frequently.