Investors in a Vanguard target-date mutual fund got a nasty surprise last month when they were hit with a whopping tax bill for capital gains. They're not alone.

Data compiled by CapGainsValet shows that in 2021, a record number of mutual funds made larger-than-average capital gains distributions. Gains are recorded when fund managers sell some of their appreciated holdings, often to give departing investors their money back or to buy different investments.

Some investors forget: With mutual funds you're on the hook for capital gains taxes not only when you sell your own shares for a profit, but also if the fund itself sells assets that have gone up in value. The fund will tally up its activity and typically make an annual payout, often at the end of the year. You could owe tax even if you reinvested your gains back into the fund, and they'll often be subject to long-term capital gains rates.

It's a nonissue for anyone holding mutual funds in a retirement account, such as a 401(k) or IRA, since taxes are owed only when withdrawals begin. For those with mutual funds held in a taxable account, such as one with a brokerage firm, it's a different story.

Investors who are worried about their tax liabilities should consider exchange traded funds, or ETFs, which don't come with the same tax baggage. More on that later.

The saving grace in 2021 was that most funds performed well — so even if you had to pay some unanticipated capital gains taxes, the fund's returns hopefully softened the blow. For example, the Vanguard 2035 retirement fund that infuriated its investors with eye-popping tax bills returned 13% (before taxes).

What made investors in the Vanguard retirement fund particularly upset was that the company was effectively responsible for the capital gains distribution. It decided to lower the investing minimum for its cheaper share class, which prompted a bunch of investors to abandon the more expensive one, triggering a wave of sales and taxable gains.

Today, we're in a different situation. Many funds are struggling because of the market volatility this year, and if outflows continue, you could face the double whammy of fund losses plus a big capital gains distribution as more fundholders jump ship.

Investors often focus on a fund's fees, but research from Morningstar shows for U.S. stock funds the reduction in returns from taxes triggered by fund distributions is 1.7% on average — almost double the hit investors take from annual expenses.

In addition to Vanguard's, funds including Franklin U.S. Large Cap Equity Fund, American Century Equity Growth Fund, Goldman Sachs U.S. Equity Insights and J.P. Morgan U.S. Large Cap Core Plus Fund also had to make hefty capital gains distributions — and that's just to name a few, according to CapGainsValet.

So how can an investor minimize the tax pain when it comes to mutual funds? For new money you want to invest, the easiest answer is reserve those funds that are most likely to have internal capital gains distributions for your 401(k) or another tax-deferred retirement account. That would include target-date funds, which have to rebalance and sell stocks to buy bonds as you get closer to retirement, and actively managed stock funds because managers may make a lot of trades.

But that doesn't help wealthier investors who have already maxed out their retirement contributions.

They'd be wise to rely on ETFs that track broad indexes. Because of the way ETFs are structured and traded, the fund doesn’t have to sell assets to raise cash to meet redemptions, which means investors don't have to worry about tax hits caused by others heading for the exit. ETFs have long been touted for their tax efficiency, but today's environment makes them even more so.

Many people are attracted to target-date funds because they can just set them up and forget about them; the fund does all the rebalancing automatically as their retirement date nears. That may be true, but if you're tax sensitive, and given the likelihood for big capital gains distributions, why not just buy a few different ETFs and diversify your portfolio yourself? Or if you have considerable assets, pay a financial adviser to do so.

If you're still intent on investing in a target-date fund or another mutual fund outside your 401(k), then look for those that say they are tax-managed or tax-efficient. Generally if one of those phrases is in the title of the fund, it means that managers will try to keep distributions, and hence, taxes, to a minimum. Check the fund's prospectus to be sure.

But you should know, there's only so much a mutual fund manager can do if there's an onslaught of redemptions, so even tax-managed funds could eventually have to make distributions, says Mark Wilson, a certified financial planner in Irvine, California.

For anyone who is currently invested in a fund that made a big distribution last year, proceed with caution. If you've held the fund for a while, selling now would be foolish since you're likely to incur capital gains of your own making. You may be in the driver's seat, but the tax pain could be a lot worse.

Alexis Leondis is a Bloomberg Opinion columnist covering personal finance. Previously, she oversaw tax coverage for Bloomberg News.