The number that measures your gain is the adjusted basis, not the cost, and Publication 551 says so structurally. It states that before figuring gain or loss on a sale, exchange or other disposition of property, or figuring allowable depreciation, depletion or amortization, you must usually make certain adjustments to the basis of the property, and that the result of those adjustments is the adjusted basis. There is no separate page on this site for adjusted basis, so the essentials belong here.
Basis goes up for items properly added to a capital account. Publication 551 gives capital improvements with a useful life of more than a year, such as an addition, a replaced roof or a paved driveway; assessments for local improvements such as water connections, sidewalks and roads; certain legal fees; and costs of restoring property after a casualty. For securities, the everyday additions are purchase commissions and, above all, reinvested distributions.
Basis goes down for things you have already received the benefit of. Publication 551 lists depreciation, section 179 deductions, casualty and theft loss deductions and insurance reimbursements, certain vehicle credits, exclusions from income for energy-conservation subsidies, and nontaxable corporate distributions. That last one is the return of capital that arrives as a nondividend distribution: it is not taxed when received precisely because it reduces basis instead, and the tax shows up as a larger gain later.
Reinvested dividends are the adjustment that costs real money, and they are missed constantly. If a fund distribution is reinvested, the distribution was taxable in the year it was paid and the shares it bought have their own basis equal to what was paid for them. Forgetting to add those amounts means paying tax twice on the same dollars, once as income when they were distributed and again as capital gain when the shares are sold. Publication 550 makes the underlying point about dividend reinvestment plans directly: where dividends are used to buy more stock at fair market value, the dividends are still reported as income.
Broker reporting has a hard line through it, and the line is not what folk wisdom says. IRC 6045(g) requires brokers to report adjusted basis on a sale only for a covered security, defined as a specified security acquired on or after an applicable date. Those dates are set by 6045(g)(3)(C): 1 January 2011 for stock in a corporation generally, 1 January 2012 for stock for which an average basis method is permissible, which is how mutual fund shares are reached, 1 January 2013 or a later date the Secretary determines for other specified securities such as debt instruments and options, and 1 January 2023 for digital assets, whose reporting has been phased in by regulation with gross proceeds first and basis following. Dividend reinvestment plan stock acquired before 2012 is pulled into the mutual fund date by 6045(g)(6).
What that means in practice is that basis for anything acquired before the relevant date is noncovered, and it is the taxpayer's responsibility to establish, whether or not the broker has it. So the folk claim that brokers lose your basis when you move accounts misdirects. IRC 6045A requires a transfer statement carrying basis information to follow covered securities from one broker to the next, so a transfer does not sever the record for anything covered. The real gap is age, not movement, and it is a reason to keep your own records of long-held positions independently of any statement.
The lot identification election is made at or before the sale, not at filing time. Where shares of the same stock were bought on different dates or at different prices, Treasury Regulation 1.1012-1(c)(1)(i) provides that if the taxpayer does not adequately identify the lot being sold, the sale is charged against the earliest lot acquired, which is the first-in, first-out default. For shares held with a broker, 1.1012-1(c)(3) makes an adequate identification one where, at the time of the sale or transfer, the taxpayer specifies to the broker which particular shares are to be sold, with a written confirmation following. IRC 6045(g)(2)(B)(i) mirrors this on the reporting side, applying first-in, first-out unless the customer notifies the broker by making an adequate identification, and applying the broker's default method for average-basis-eligible stock unless the customer elects another. Naming the available methods without the timing tells a reader they have a choice they have in fact already lost, because the moment to exercise it was before the sale settled.
Basis other than cost covers the routes where nothing was paid. Inherited property is generally reset to its fair market value at the date of death under IRC 1014, which is the step-up in basis and a large planning consideration in its own right. Property received as a gift generally carries the donor's basis across to the recipient, with special rules where the property's value has fallen below that basis. Shares acquired through employer compensation plans have their own basis rules, and the double-counting risk there is covered on the pages for those plans.