Do you pay capital gains selling investments to buy a house?

Trying to figure out if the reason you sell stocks matters for taxes. I have a brokerage account with some index funds I've held for about 3 years and want to sell them to put together a down payment on a house. Total gain would be maybe $40k above what I paid. I know there's a capital gains exclusion when you sell a home you lived in, but does that apply here? Or is it only about the house you're selling, not what you're buying? I already looked at Schedule D and Form 8949 and I see where the gains go, but I can't find anything that says the purpose of the sale changes anything. Someone at work told me you can avoid the tax if you're buying a primary residence. That doesn't sound right to me but I wanted to ask here before I do anything.

38 comments

Your coworker is thinking of the old rollover rule that existed before 1997. That was eliminated a long time ago. Today, when you sell stocks or funds in a taxable brokerage account, you owe capital gains tax on the profit — full stop. What you do with the money afterward doesn't change that. The IRS doesn't carve out an exception because the proceeds are going toward a home purchase.

Monica P.

Author

That's what I suspected. So the home exclusion in Publication 523 is only about selling a home you already own and lived in, not about buying one?

Exactly. The exclusion in Publication 523 is for gain on the sale of your main home — it shields a portion of the profit you make when you sell a house you owned and used as your residence. It has nothing to do with what you buy next or why you're selling other assets.

Is your brokerage already calculating your gain correctly? I ask because I ran into a situation where my 1099-B showed the wrong cost basis for some older shares — fund company had bad records from before electronic tracking. I uploaded my 1099-B to taxr.ai and it flagged which lots had basis marked "not reported to IRS" (box E on Form 8949 for long-term lots like those, box B for short-term ones) versus which were covered. Helped me figure out where I needed to supply my own records. Worth checking before you assume the number on your statement is what the IRS will see.

How long have you held the funds exactly? You said about 3 years but the difference between short-term and long-term is real money here. 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. If every lot is over a year you're in long-term territory, which is taxed at a lower rate than ordinary income. The Form 8949 instructions and Schedule D walk through how to separate short-term lots (Part I) from long-term (Part II).

Monica P.

Author

All the lots are well over a year, the oldest ones are from 2021. So those should all go in Part II of Form 8949 under box D or E depending on whether the broker reported the basis.

Right. If your broker reported the basis to the IRS (covered securities) you check box D. If not, box E, and you enter the correct basis yourself in column (e). Either way the gain flows to Schedule D Part II and gets combined with any other long-term items on line 8a or below.

Does your state have its own capital gains tax on top of federal? A few states don't distinguish between short and long term at all and just tax investment gains as ordinary income. That could change the total bill noticeably depending on where you live.

Monica P.

Author

Good point, I should check my state rules separately. The federal side is what I was focused on but you're right that it stacks.

Worth noting: even if you can't avoid the tax, you can sometimes time it. If you have any positions sitting at a loss in the same account you could harvest those losses to offset some of the gain. The loss offsets the gain dollar for dollar on Schedule D before you get to any net number. Just watch the wash sale rule — if you sell something at a loss and then buy the same or substantially identical security within 30 days before or after, the loss is disallowed and gets added to the basis of the replacement shares instead.

Monica P.

Author

I do have one fund that's slightly underwater. So I could sell that at a loss in the same year and that loss reduces the net gain on Schedule D before tax is calculated?

Yes, that's how it works. Long-term losses offset long-term gains first, then net long-term against net short-term. The Schedule D instructions walk through the netting order. Just be sure you don't repurchase the same fund within 30 days or the wash sale rule kills the loss deduction.

Are you liquidating everything at once or spreading the sales across two tax years? If your gain is large enough that timing it over December and January would split it across two returns, that's sometimes worth modeling — especially if your income varies year to year and that affects which bracket you land in for the gains. Not always worth it depending on when you need the down payment, but worth running the numbers.

Monica P.

Author

The house timeline is tight so I probably can't split it, but that's a good thing to keep in mind for the future.

To confirm what others said: there is no provision in the tax code that exempts capital gains just because you're using the proceeds to buy a primary residence. The home sale exclusion in Publication 523 at irs.gov applies to the gain on selling a home you owned and lived in — not to the sale of investment assets you're liquidating to fund the purchase. Topic 409 on the IRS site lays out how capital gains and losses work generally, and Publication 550 covers the investment side in detail.

When I sold a mix of ETFs and individual stocks a couple years back I had some lots where the broker's basis was just wrong — they had me down for a higher per-share cost than I actually paid, which would have meant I underreported the gain. I pulled all my trade confirmations and had Taxr read through them alongside the 1099-B to list every discrepancy lot by lot. It drafted a column (g) adjustment summary I could use when filling out Form 8949. I still reviewed everything and entered it myself, but having the comparison laid out clearly saved hours.

Monica P.

Author

That's actually my worry too — I bought some of these funds in multiple small purchases over the years and I'm not sure my broker is using the right cost basis method. I'll pull my old confirmations.

Check whether your broker has you set to average cost, FIFO, or specific identification. With specific ID you can choose which lots to sell, which lets you pick lots with the highest basis to minimize the gain — but you have to designate which lots at the time of sale, before the trade settles, not after.

My situation is a little different — what if someone inherited shares and is now selling them to buy a house? Does the basis work the same way?

Inherited shares get a step-up in basis to the fair market value at the date of the decedent's death (or alternate valuation date if the estate chose it). So the taxable gain is only what the shares appreciated after you inherited them. And inherited property is treated as long-term regardless of how long you personally held it — that's spelled out in Publication 550.

Stepping back — so the holding period question doesn't apply to inherited shares at all? They're automatically long-term from day one?

Correct. Inherited property gets long-term treatment no matter how soon you sell after inheriting. The basis rules and the holding period rule both come from Publication 551 and Publication 550 respectively. The "buying a house" part still doesn't change anything though — gain is gain regardless of what you do with the proceeds.

One thing I haven't seen mentioned: estimated taxes. If you're going to have a big gain mid-year and you're not having anything withheld from a brokerage sale, you may want to look at whether you need to make a quarterly estimated payment. Underpayment can trigger a penalty. The Form 1040-ES instructions explain how to figure whether you owe one.

Monica P.

Author

Oh, I hadn't thought about estimated payments at all. I'm a W-2 employee so I figured withholding covered me, but a one-time large gain might change that. I'll look at the 1040-ES worksheet.

W-2 withholding does help but a large capital gain on top of your salary could mean your withholding falls short. The safe harbor rules in the 1040-ES instructions tell you the threshold where you're protected from the penalty even if you end up owing — worth checking your situation against those numbers before the sale.

Coming at this from the opposite direction — I sold mutual funds last year and tried to figure out which Form 8949 box to check and whether my broker had reported the basis correctly. I had Taxr walk through my 1099-B box by box and it flagged that two of my lots were showing code B (incorrect basis) in column (f) and told me I needed to enter the broker's wrong number in column (e) and then correct it with a negative adjustment in column (g) since my actual basis was higher. That's the procedure when box D is checked and basis was reported to the IRS but it's wrong — you don't just put the right number in, you show the correction.

Monica P.

Author

Wait, so even if you know the basis is wrong, you still enter the broker's number first and then adjust? That seems counterintuitive.

Yes, when box D or E is checked it matters which one. Box D means basis was reported to the IRS — in that case you enter what the 1099-B shows in column (e), then put the correction as a negative number in column (g) if your real basis is higher. Box E means basis wasn't reported, so you just put the correct number in column (e) directly.

Are you planning to reinvest dividends in these funds before you sell? If so, each reinvested dividend bought additional shares at different prices and those are separate lots with their own basis and holding period. Easy to miss a few of those in the cost basis calculation, especially if the fund has been paying quarterly dividends for years.

Monica P.

Author

I do have DRIP turned on and I hadn't thought about that at all. Each reinvested dividend is its own lot? So I might have dozens of tiny lots in addition to my original purchases?

Yes, every reinvested dividend is a purchase of new shares at the NAV on that date, with its own cost basis equal to the amount reinvested. Your broker should be tracking all of these if the shares are covered securities, but it's worth pulling the history and verifying, especially for older lots that might be noncovered.

What about state withholding on the brokerage side? Some states require brokers to withhold state tax on certain redemptions for in-state residents. Worth checking with your broker before the sale so you're not surprised at year end.

Covered securities side of things — the state treatment really does vary a lot. Some states piggyback exactly on federal, some have their own holding period rules, some tax capital gains as ordinary income at the full rate. State revenue department's instructions for the state equivalent of Schedule D are the place to look.

Put practically, the answer is yes: you pay capital gains tax when you sell investments regardless of what you plan to do with the money. The IRS has no "I'm buying a home" exception for investment sales. The only relevant exceptions would be if you had capital loss carryovers from prior years to offset the gain, or if you're harvesting losses in the current year as mentioned above. Both of those reduce the net taxable gain on Schedule D — they don't eliminate the obligation to report the sale on Form 8949.

How large is the total sale going to be? I ask because if you're liquidating a significant amount in one year it might be worth having a CPA or enrolled agent run the numbers, especially if you have DRIP lots, prior year loss carryovers, state tax, and estimated payment questions all in play at once. Each of those pieces interacts with the others and a mistake on Form 8949 — especially cost basis — can be hard to unwind after the fact.

Monica P.

Author

Probably around $150k total proceeds. Given all the DRIP lots and the basis questions I think you're right that I should at least have someone review my Form 8949 before I file. I'll look for a CPA who handles investment returns.

The $3,000 capital loss deduction limit only kicks in if your losses exceed your gains and you end up with a net loss on Schedule D line 16. In that situation you can only deduct up to $3,000 against other income (or $1,500 if married filing separately) and carry the rest forward. But if you have a net gain like the original poster does, you're not hitting that rule — you just owe tax on the net gain.

Correct on the carryforward mechanics. And the carryover keeps its character — long-term loss carryover stays long-term and offsets long-term gains first in the next year. The Capital Loss Carryover Worksheet in the Schedule D instructions shows how to figure the amount.