One way to get wealthy in the stock market is to take dividend-paying stocks and reinvest the quarterly payments they make into buying more shares. Dividend reinvestment plans, or DRIPs for short, make it simple for investors in many dividend stocks to use this strategy. But at tax time, it can difficult to calculate your cost basis when you eventually decide to sell the shares you've accumulated over a lifetime of dividend reinvestment. Below, we'll go through a process you can use to calculate your cost basis and ensure that you don't pay more in taxes than you should.

How dividends get taxed
The main thing to remember about DRIPs and taxes is that any time you receive a dividend payment in shares held outside a tax-deferred account like an IRA, you'll have to include the dividend in taxable income. That's true even if you take the dividend and use it to buy new shares through a DRIP. In other words, just because you never see a penny of cash doesn't mean that you escape tax liability.

The benefit of having to pay tax on your current dividend income is that you get to increase the tax basis of your position in the dividend stock. The shares that you buy through dividend reinvestment have a basis equal to the amount of dividends you gave up to obtain them. As a result, over time, your total cost basis in your position will rise.

Eventually, when you sell your shares, your capital gain will be the difference between the proceeds from the sale and your cost basis in the shares. It's critical to increase your cost basis by the amount you've been taxed for your dividends along the way, or else you'll overpay on capital gains taxes at sale.

Tracking your cost basis
The simplest way to keep track of your cost basis is to note the amount of dividends on which you're taxed from year to year. By adding those amounts to what you originally paid for shares, you'll accurately reflect your total cost basis for the position. Some DRIPs will even keep track of your cost basis information for you.

What gets tricky is if you decide to sell only a portion of your shares. In that case, you'll have to choose which method to use in selecting the exact shares that you sell. Using a method like first in, first out will generally get you long-term treatment for any gains or losses, but if the stock has risen over time, that method will sometimes lead to larger taxable gains than others. By contrast, specific identification can allow you to choose shares with smaller gains, but you might not have held those shares long enough to get preferential long-term treatment.

The key aspect of calculating cost basis for DRIPs is that a little recordkeeping along the way can save a lot of time later on. It can even save you from making what could become a costly tax mistake when you sell your shares.

Are you ready to dive into investing? Check out The Motley Fool's Broker Center and get started today.

This article is part of The Motley Fool's Knowledge Center, which was created based on the collected wisdom of a fantastic community of investors. We'd love to hear your questions, thoughts, and opinions on the Knowledge Center in general or this page in particular. Your input will help us help the world invest, better! Email us at [email protected]. Thanks -- and Fool on!