How to manage long-term capital gains in taxable brokerage with Social Security

Retired last year, collecting Social Security now, and I have a taxable brokerage account with a mix of positions I've held more than a year. I want to start trimming some winners but I keep reading that long-term capital gains can affect how much of my Social Security gets taxed. I ran the numbers roughly on Schedule D but I can't figure out where the two things connect — like, does the gain on Schedule D actually feed into the Social Security calculation, or is it something else? I already know the 0%/15%/20% rate brackets exist but I don't know how to manage long-term capital gains in taxable brokerage with Social Security without accidentally bumping a big chunk of my benefits into taxable territory. Is there a worksheet I should be working from?

38 comments

Schedule D line 16 (net capital gain or loss) flows to Form 1040 line 7a, which is part of your total income. That total income is then used in the Social Security worksheet — specifically the combined income calculation. Combined income is adjusted gross income plus nontaxable interest plus half of your Social Security benefits. Long-term gains raise AGI, which raises combined income, which can push more of your SS into the taxable range. The worksheet is in the Form 1040 instructions under "Social Security Benefits Worksheet."

Greg K.

Author

So the connection is through AGI, not a separate form. That makes sense — the gain on Schedule D hits line 7a, which is part of AGI, and AGI is in the combined income formula. I need to model what a partial sale does to that number before I sell anything.

If you want the official word on how gains and losses are reported and how they flow through the return, the IRS lays it out in Publication 550. Worth reading the capital gains chapter before you start selling. The holding period section is clear: for securities traded on an established market, your holding period starts the day after the trade date you bought and ends on the trade date you sell. So if you're right on the edge of long-term, make sure you're counting from the right date.

Greg K.

Author

I'm well over a year on most of these positions so the long-term part isn't the issue, it's the AGI impact.

The key thing people miss is that even a 0% long-term capital gains rate doesn't protect you from the Social Security taxation threshold. The 0% rate on the gain itself is real — you pay no federal income tax on the gain — but the gain still counts in AGI, which still counts in combined income for the SS worksheet. So you can have a "tax-free" gain that makes more of your benefits taxable. Those extra dollars of SS income then get taxed at your ordinary rate.

This tripped me up badly in my first year of retirement. I sold a bunch of shares thinking the 0% rate meant no tax consequences at all.

Greg K.

Author

Ugh, that's the scenario that had me nervous. So the 0% rate is on the gain, but the downstream effect on SS can still create a real tax bill.

I uploaded my 1099-B and my Social Security benefit statement to taxr.ai and asked it to walk through how each planned sale would change my AGI and feed into the SS worksheet. It mapped out which lots would push combined income past the first threshold and which I could sell without triggering extra SS taxation on my specific numbers. That kind of line-by-line check before selling is exactly what I needed. The rule itself is in the Form 1040 instructions — the SS Benefits Worksheet shows the two thresholds and the percentages.

Greg K.

Author

Did it account for different lot sizes, like selling partial positions? That's what I need to figure out — how much I can take before the threshold moves.

Yes, I gave it the specific lot quantities I was considering and it recalculated combined income for each scenario. It drafted a comparison table so I could see the before and after for each lot.

Worth knowing: the two SS thresholds (the points at which 50% and then 85% of your benefits become taxable) are fixed dollar amounts that don't adjust for inflation, so they bite more people every year. The Form 1040 instructions have the exact figures for the year you're filing. Plan around your specific combined income, not a general rule of thumb.

Form 1040 instructions, Social Security Benefits Worksheet — the thresholds are right there, and they haven't changed in decades. A lot of retirees don't realize they're not indexed.

One approach some people use: spread sales across two calendar years instead of selling everything at once. If your combined income is close to a threshold in year one, holding some lots until January gives you a fresh calculation for year two. Each year's SS worksheet is independent.

Greg K.

Author

Social Security Benefits Worksheet — does each year really reset completely? I assumed carryforward losses might complicate it.

Capital loss carryforwards do reduce your gains in future years, which lowers AGI, which lowers combined income. That actually helps. The SS worksheet itself just looks at that year's AGI plus nontaxable interest plus half your SS. No multi-year memory in the SS calc itself.

Don't forget qualified dividends. They also count in AGI and also benefit from the same 0%/15%/20% rate structure as long-term gains, but they hit combined income the same way. If your brokerage account throws off significant qualified dividends, that's already eating into your headroom before you sell anything.

Greg K.

Author

Qualified dividends — yes, I have a lot of those too. So my "available room" before the SS threshold is already smaller than I realized.

If you have any positions with unrealized losses, harvesting those losses before year-end reduces your net capital gain on Schedule D line 16, which reduces AGI, which reduces combined income. Topic no. 409 on irs.gov covers capital gains and losses including how losses offset gains. The wash sale rule at Publication 550 is the main trap — if you sell at a loss and buy substantially identical securities within 30 days before or after, the loss is disallowed and you don't get the AGI reduction you planned on.

Wash sale rule caught me once. Sold an ETF at a loss and bought a very similar one in my IRA within the 30-day window. The loss was disallowed because the IRA purchase counts.

Publication 550 is explicit on that — a purchase of substantially identical stock in an IRA or Roth IRA within the 30-day window triggers the wash sale. And the disallowed loss doesn't get added to the new stock's basis in that case; it's just gone.

Form 8949 is where the individual transactions land — Part II for long-term. Schedule D summarizes it. Neither form does the SS calculation; that's entirely in the Form 1040 instructions worksheet. The two calculations are separate but connected through AGI.

Roth conversions are another thing that can wreck this plan. If you're doing Roth conversions in the same year you're harvesting gains, the conversion amount is ordinary income and also hits AGI and combined income. Plan them together or one will undo the headroom the other created.

Greg K.

Author

Roth conversions — I'm not doing those this year but good to flag for future planning.

I ran through almost this exact situation last year. What helped me was uploading my prior year 1040 and my brokerage year-end statement to Taxr and having it estimate the combined income change for different sale amounts. It identified that I had a capital loss carryforward from two years earlier that I had forgotten about, which gave me more room than I thought. Worth checking your Schedule D from prior years for any carryforward amount on line 14.

Greg K.

Author

Schedule D line 14 — I'll pull that from last year's return right now. I may have a small carryforward I'm not accounting for.

Even a modest carryforward offsets current gains dollar for dollar on Schedule D before the net flows to AGI. Check it before you model anything.

State taxes are a separate question. Some states don't tax Social Security at all; some don't tax long-term gains. The federal answer (Schedule D → AGI → SS worksheet in Form 1040 instructions) is what this thread is about, but your state calculation may be very different.

Good point. The federal SS taxation rules are what most people are stuck on, but state treatment can swing the actual net result significantly.

Before I sold anything last spring I uploaded my draft 1040, my 1099-B, and my SSA-1099 to Taxr and asked it to check whether my planned sales would cross either SS threshold. It flagged that two of my planned lots, sold together, would push combined income just past the first threshold and suggested I defer one lot to January. I ended up saving real money on the SS taxation side just by timing the second sale. The SSA-1099 box 5 is what feeds the SS Benefits Worksheet — that's your net SS benefit amount.

Greg K.

Author

SSA-1099 box 5 — I have that form. So box 5 is the number that goes into the worksheet, not the gross benefit?

Box 5 is net benefits for the year — the benefits paid in box 3 minus any benefits you repaid in box 4, and it still includes any Medicare premiums withheld from your payments. That's the figure the worksheet uses. Half of that goes into the combined income formula.

If your gains are large enough that you might hit the 15% or 20% long-term rate threshold, or if the SS exposure is substantial, it's worth sitting down with a CPA or enrolled agent who does retirement income planning. The interaction between capital gains, SS taxation, Medicare premium surcharges (IRMAA), and RMDs if you have traditional IRAs can get complicated fast and a wrong move in one area can cost more than the gain was worth.

Greg K.

Author

IRMAA hadn't even crossed my mind. So capital gains affect Medicare premiums too, through AGI. This is getting complicated enough that I think you're right about the CPA.

Form 8949, Part II, column (h) shows your long-term gain or loss per transaction, and the totals go to Schedule D Part II, lines 8a through 10. Those lines, plus lines 11 through 14, combine on line 15, then line 16. Line 16 is what flows to Form 1040. If you want to know exactly how much gain you can realize before hitting a threshold, work backward: start from the threshold, subtract your other AGI items (ordinary income, dividends, etc.) and your half-SS, and what's left is your available room for gains.

That backward calculation is the right way to do it. Most people try to do it forward and overshoot.

Greg K.

Author

Schedule D line 16 back to Form 1040 — working backward from the threshold makes a lot more sense. I'll build a simple spreadsheet with that logic.

Publication 550 has a chapter on investment income and expenses that covers holding periods, how losses offset gains, and what flows to Schedule D. It's the most complete single reference for the brokerage account side of this question. The IRS page for it is at irs.gov/publications/p550.

Topic no. 409 on irs.gov is a shorter read if you just want the capital gains and losses basics without the full publication.