Realized vs unrealized
If your stock rises from 50 to 80 dollars, you have an unrealized gain. It becomes a capital gain for tax only when you sell. Selling at 80 realizes a 30 dollar gain per share.
Short term vs long term
In the US the holding period decides the rate. Gains on investments held one year or less are short-term and taxed like ordinary income. Gains on investments held more than one year are long-term and taxed at lower rates. Rates and brackets change, so check irs.gov.
Cost basis
Your cost basis is what you paid, including reinvested dividends. Gain equals sale price minus basis. If you bought shares at different prices, brokers track lots and let you pick a method. Keep your records.
Losses can help
Capital losses offset capital gains, and some excess loss can offset other income, with limits. This is the idea behind tax-loss harvesting. The wash sale rule disallows a loss if you rebuy the same security too soon.
Dividends and funds
Dividends are taxed too, at different rates depending on whether they are qualified. Funds can also pass on capital gains distributions. In general, ETFs and index funds trade less, so they tend to distribute fewer gains than actively managed funds.
Ways people reduce the bite
Quick answers
Do I owe tax if I reinvest the proceeds?
Yes. Selling is the taxable event, even if you buy something else right away.