He Will Sell Stock at a $40,000 Loss to Cancel Out the $40,000 He Takes From the 401(k). The IRS Will Allow $3,000 of It. Medicare Will Read the Other $37,000

Taking money from a 401(k) and selling a losing stock in the same year sounds like a clean offset, but the tax code treats them as two completely different events, and Medicare may end up counting more of that income…

Published October 14, 2026, 4:30pm ET · 4 min read

The Full Benefits Desk desk. Editor: Gerelyn Terzo.

This post may contain links from our sponsors and affiliates, and Flywheel Publishing may receive compensation for actions taken through them.

Unhappy Senior Man Thinking About Retirement Sitting On Sofa
Unhappy Senior Man Thinking About Retirement Sitting On Sofa © Unhappy Senior Man Thinking About Retirement Sitting On Sofa (Shutterstock.com) by Prostock-studio

Major indexes may be hovering near records, but his brokerage account still has a $40,000 loser. He is determined to make the best of it. He takes $40,000 from his 401(k) and sells stock at a $40,000 loss, expecting one to wipe out the other. The tax code handles the two differently, and Medicare can end up seeing $37,000 of additional income.

Whether that hurts depends on where his income already sits. The Centers for Medicare & Medicaid Services (CMS) says income-related surcharges affect roughly 8% of people with Medicare Part B. In 2026, the surcharge starts above $109,000 of modified adjusted gross income (MAGI) for single filers and above $218,000 for joint filers. A retiree well below those lines can harvest losses without worrying about Medicare, but one within about $40,000 of a threshold needs to know how the loss and withdrawal actually interact.

A $40,000 Capital Loss Does Not Cancel $40,000 of 401(k) Income

A distribution from a pretax plan is generally fully taxable as ordinary income in the year he takes it. The stock loss follows a separate set of rules. Under 26 U.S.C. § 1211(b), capital losses first offset capital gains. Once the gains run out, he can deduct no more than $3,000 against ordinary income ($1,500 for a married person filing separately). The $3,000 cap applies to single filers and married couples filing jointly alike.

The leftover loss remains available. Under 26 U.S.C. § 1212(b), it carries forward into later years.

Follow the $37,000 Into Medicare MAGI

In this simple example, $40,000 of taxable 401(k) income minus the $3,000 deduction raises his AGI by $37,000. Social Security then defines MAGI as total adjusted gross income and tax-exempt interest income. That add-back surprises a lot of retirees: municipal bond interest feels tax-free, but it still counts toward IRMAA.

Say he files single and his MAGI is $85,000 before these moves. Add the $37,000 and his MAGI reaches $122,000. Using the 2026 table as a yardstick, that is $13,000 over the first threshold and inside the tier that runs above $109,000 and up to $137,000. At 2026 rates, that tier adds an $81.20 monthly Part B surcharge, or $974.40 a year, plus a separate $14.50 monthly Part D surcharge.

Medicare looks back two years, so a 2026 withdrawal sets his 2028 IRMAA. The 2028 brackets haven’t been published yet and will reflect inflation adjustments, so use the 2026 lines as a guide, and since 2026 income remains open until December 31, he still has about 11 weeks to change the outcome.

Don’t count on Form SSA-44 as a fallback. It covers income drops caused by qualifying life events like retirement, divorce or a spouse’s death. A voluntary 401(k) withdrawal doesn’t qualify. Married readers should also know about the survivor trap: a widow or widower who starts filing single faces the $109,000 threshold instead of $218,000, even if household income remains the same. IRMAA is just a Medicare pricing quirk tied to income from two years back, and we covered the rest in a free guide to Medicare’s hidden bills.

When the Full Loss Can Help More

The loss does far more work when he has realized gains to offset. If he sold a fund earlier in the year for a $40,000 gain, the $40,000 loss wipes out that gain completely, keeping $40,000 out of AGI instead of $3,000. The 401(k) withdrawal still counts in full. What the loss does is cancel income that would otherwise stack on top of it.

Carryforwards from earlier years work the same way and combine with new losses, so check last year’s Schedule D before selling anything. Losses inside an IRA or 401(k) produce no deduction at all, because those accounts sit outside the taxable-account rules.

Coordinate the Sale With the Withdrawal Before December 31

  • Pull a realized gain and loss report, which your brokerage tracks as year-to-date figures. Add any carryforward from your 2025 return, then see how much loss can offset real gains this year.
  • Size the withdrawal to the threshold. In the example, a $27,000 withdrawal plus the $3,000 deduction leaves his MAGI right at $109,000. Under the 2026 table, $109,000 or less pays the standard premium. Run the withdrawal and the stock sale through the same projected return. Don’t assume matching dollar amounts cancel each other.
  • Leave yourself a margin. Even a small one could matter. December mutual fund distributions, dividends and interest can push MAGI over a tier by a few hundred dollars. Going one dollar over triggers the full surcharge. If your projected MAGI lands within $20,000 of a bracket and you’re considering larger withdrawals or Roth conversions, a fee-only advisor who specializes in tax-efficient retirement income can model the next several years together.

The mistake is treating two $40,000 numbers as tax opposites. One is ordinary retirement income. The other is a capital loss with its own limits, and Medicare sees the difference.

Contact [email protected] for any questions or corrections.

Gerelyn Terzo

Gerelyn Terzo is the author of dividend investing handbook "Dividend Investing Strategies: How to Have Your Cake & Eat It Too." A veteran financial journalist, she covers agri-finance for outlets like Global AgInvesting and the broader stock market and personal finance for 24/7 Wall Street. She began at CNBC and later helped launch Fox Business in New York. Gerelyn currently resides in Woodland Park, Colorado and dabbles in nature photography as a hobby.

All articles →