Although you reinvest dividends, you receive them first - and they get taxed. So if you get 2% in dividends per year, you might owe 0.3% of the fund's assets in taxes (15% of the dividend).
Over 20 years, you have investments made 1 year ago and investments made 20 years ago. The investments from 20 years ago might have quadrupled, while recent investments are randomly up or down some amount.
If you sold your oldest investment first (probably a bad idea), and it had quadrupled since you bought it, you have:
25% your original investment
75% growth on that investment
So you would pay 15% capital gains on the 75% that grew (about 11%), not the original money you put in. But you can improve on that by taking an investment just over 1 year old, with maybe only +20% in gains. For that more recent investment:
83% original investment
17% growth on original investment (17 / 83 = about 20%)
So selling something a more recent investment might mean paying 15% tax on just 17% of the investment (about 2.6%). By selecting more recently bought shares, you could reduce taxes significantly.