Investment Tax

How Is Tax Calculated When Selling Stocks?

When you sell stock for more than your adjusted cost basis, the difference can create a capital gain. The important part is determining the correct basis for the shares you actually sold.

This article explains how tax is calculated when selling stocks, including cost basis, holding period, short-term vs long-term gains, and key tax considerations.

⚑ Quick Answer

A simplified stock-sale calculation is:

Sale Proceeds βˆ’ Adjusted Cost Basis = Capital Gain or Loss

Example: Sell shares for $20,000. Adjusted basis: $14,000. Estimated gain: $6,000.

Important: The $6,000 is the gain, not automatically the tax owed. The final tax result can depend on holding period, taxpayer's income, applicable tax rules, state tax, and other capital gains/losses.

Do You Pay Tax When You Sell Stocks?

Yes, selling stocks can create a taxable capital gain. However, the actual tax you may owe depends on several factors:

Understanding these factors is essential before estimating potential tax consequences.

How Is a Stock Capital Gain Calculated?

The capital gain or loss from selling stocks is calculated using a straightforward formula:

Sale Proceeds βˆ’ Adjusted Cost Basis = Capital Gain or Loss

If sale proceeds exceed adjusted basis, you have a capital gain. If adjusted basis exceeds sale proceeds, you have a capital loss.

What Is Cost Basis?

Cost basis is generally the amount you paid for the shares, plus certain acquisition costs. Common components include:

Brokerage records can be useful for determining basis. Keep trade confirmations and account statements for reference.

What Is Adjusted Cost Basis?

Your cost basis may need adjustments because of certain events. Possible adjustments include:

Important: The taxpayer should verify the basis rather than blindly relying on an incomplete record. Broker-reported basis may not reflect all adjustments.

How Does the Holding Period Affect Stock Gains?

The holding period determines whether a gain or loss is generally treated as short-term or long-term:

Holding Period Distinction
Short-Term Held for 1 year or less
Long-Term Held for more than 1 year

The holding period generally starts the day after you acquire the shares and ends on the day you sell them. The distinction can affect the tax treatment of your gain or loss.

Short-Term vs Long-Term Capital Gains

Under current federal tax rules, short-term and long-term capital gains may receive different tax treatment:

Tax Treatment Comparison
Short-Term Gains Generally taxed as ordinary income
Long-Term Gains May qualify for preferential rates

The applicable tax rate depends on the taxpayer's income, filing status, and other factors. Consult current IRS guidance for specific rates.

What If You Bought Shares at Different Times?

A taxpayer may buy the same stock at different prices on different dates. This creates multiple "lots" with different cost bases and holding periods.

Example:
  • Lot A: 100 shares purchased at $20
  • Lot B: 100 shares purchased at $30

If 100 shares are sold, the basis depends on which shares are treated as sold.

Identifying which shares were sold is an important part of calculating the correct gain or loss.

Specific Share Identification and FIFO

Investors may be able to identify particular shares when selling securities if applicable requirements are satisfied:

Important: You cannot retroactively choose any lot without following applicable rules. Keep broker documentation and make timely elections when required.

Do Brokerage Fees Affect the Calculation?

Certain transaction costs can affect the calculation of gain or loss. Brokerage fees paid when buying shares may be added to the cost basis. Fees paid when selling shares may reduce the sale proceeds.

The treatment can depend on the nature of the fees and applicable tax rules. Review your trade confirmations and Form 1099-B for specific information.

What Happens When You Sell at a Loss?

If sale proceeds are below adjusted basis, the transaction may produce a capital loss:

Sale Proceeds βˆ’ Adjusted Cost Basis = Capital Loss

Capital losses have their own federal tax rules. They may be used to offset capital gains and, in some cases, a portion of ordinary income. Consult current IRS guidance for specific limitations and rules.

What Is a Wash Sale?

The wash-sale rule is a federal tax provision that can affect the recognition of losses from stock sales. In general, a wash sale occurs when:

Important: The wash-sale rule can disallow the loss for current tax purposes. The disallowed loss is added to the basis of the newly acquired shares. Consult current IRS guidance or a qualified professional for specific details.

What Is Form 1099-B?

Brokers may issue Form 1099-B reporting securities transactions. This form typically includes:

Note: Review Form 1099-B carefully. The reported basis may not reflect all adjustments. Taxpayers should reconcile records when needed.

Worked Example

Let's walk through an example of calculating a stock sale gain.

πŸ“Š Example: Selling Stock

Scenario: You purchased 200 shares at $25 per share ($5,000 basis). You sell all 200 shares at $40 per share ($8,000 proceeds) with $50 in selling-related transaction costs.

Calculation
Sale Proceeds$8,000
βˆ’ Transaction Costs-$50
Net Proceeds$7,950
βˆ’ Adjusted Basis-$5,000
Estimated Capital Gain$2,950
πŸ’‘ What this means: $2,950 is the simplified estimated gain. It is NOT automatically the tax owed. The actual tax depends on the holding period, taxpayer's income, and applicable tax rates.

Second Example With Multiple Lots

This example shows how the gain can differ depending on which shares are treated as sold.

πŸ“Š Example: Multiple Lots

Scenario: You have two lots:

  • Lot A: 100 shares purchased at $20
  • Lot B: 100 shares purchased at $35

You sell 100 shares at $50 per share ($5,000 proceeds) with $25 in transaction costs.

If Lot A is Sold
Net Proceeds$4,975
βˆ’ Basis (Lot A)-$2,000
Gain$2,975
If Lot B is Sold
Net Proceeds$4,975
βˆ’ Basis (Lot B)-$3,500
Gain$1,475
πŸ’‘ What this means: The gain differs by $1,500 depending on which shares are treated as sold. This is why proper lot identification matters. This example is for illustration only and does not constitute investment advice.

Federal vs State Tax

Federal tax rules and state tax rules can differ. State tax treatment varies widely:

Do not assume every state follows federal treatment. Check your state's current rules or consult a qualified professional.

Records to Keep

Keep these records to support your stock sale calculation:

Common Mistakes

Here are some common mistakes to avoid when estimating stock sale tax:

How to Estimate Stock Sale Tax

Before filing taxes after selling stocks, use this checklist:

For a quick estimate, try our Stock Sale Tax Calculator.

Stock Sale Tax Calculator
Estimate capital gains and tax when selling stocks.
Try Calculator β†’

You may also find these related calculators helpful:

Frequently Asked Questions

Yes, selling stocks can create a taxable capital gain. The tax you may owe depends on the gain, holding period, and your overall tax situation.

Calculate as: Sale Proceeds βˆ’ Adjusted Cost Basis = Capital Gain or Loss. Sale proceeds include the amount received from the sale, adjusted for transaction costs.

Cost basis is generally the amount you paid for the shares, plus certain acquisition costs such as commissions and fees paid when buying.

Adjusted cost basis reflects changes to your original basis due to stock splits, reinvested dividends, corporate actions, and other adjustments.

Yes. The holding period determines whether a gain is treated as short-term or long-term, which can affect the tax treatment.

Short-term gains apply to assets held for 1 year or less and are generally taxed as ordinary income. Long-term gains apply to assets held for more than 1 year and may qualify for preferential tax rates.

You have multiple lots with different cost bases and holding periods. The gain or loss depends on which shares are treated as sold.

FIFO stands for First-In, First-Out. It means the earliest purchased shares are treated as sold first. This is a common default method used by brokers.

Yes, through specific identification. You may be able to choose which specific shares are being sold if you follow applicable requirements and keep proper records.

Yes. Fees paid when buying may be added to the cost basis. Fees paid when selling may reduce the sale proceeds. The treatment depends on the nature of the fees.

You have a capital loss. Capital losses may be used to offset capital gains and, in some cases, a portion of ordinary income, subject to applicable rules.

The wash-sale rule disallows a loss on a sale if you acquire substantially identical securities within 30 days before or after the sale. The disallowed loss is added to the basis of the new shares.

Form 1099-B is a tax form issued by brokers that reports securities transactions, including sale proceeds, cost basis, and holding period information.

Yes, in many states. State tax treatment varies widely. Some states have no capital gains tax, while others tax it as ordinary income. Check your state's rules.

Yes. Our Stock Sale Tax Calculator can help you estimate gain and tax based on the information you provide. Calculators provide estimatesβ€”not official tax determinations.

SB
Written by Shabnam Bano
Last Updated: August 15, 2026
Tax Year: 2026
Disclaimer: This article is for educational and informational purposes only and is not tax, legal or financial advice. Tax treatment depends on individual circumstances, applicable federal and state rules, and current tax law. Consider consulting a qualified tax professional for advice about your specific situation.

Read full disclaimer β†’