Nonresident alien selling US stock before moving back — capital gains tax question

Finishing up a work assignment in the US and heading back to my home country in about three months. I've been here on a visa for just under four years total. I have a brokerage account with US-listed stocks I bought while living here, and I'm thinking about selling everything before I leave rather than dealing with the account from abroad. I know the tax situation changes once I leave and become a nonresident alien again, but I'm not totally clear on what that means for capital gains on stock I sell while I'm still physically in the US. My broker sent a 1099-B last year and I filed a regular 1040. If I sell before I go, do I still file a 1040 and pay capital gains the normal way? Or does something change because I'm about to leave? Does the timing of the sale relative to my departure date actually matter for how I'm taxed on it?

34 comments

Sold all my US stocks about six weeks before I moved back to Germany. I was still a resident alien at that point under the substantial presence test so I filed a regular Form 1040 for that year, reported everything on Form 8949 and Schedule D exactly like any other year, and my broker sent me a 1099-B as usual. Capital gains were taxed at the standard long-term or short-term rates depending on holding period. Nothing special happened because I was planning to leave.

Maya J.

Author

This is what I was hoping to hear. So the key is whether you're still a resident alien under the substantial presence test at the time of the sale, not whether you've announced you're leaving or have a departure date booked?

The substantial presence test is what controls your status for the year. If you've been in the US long enough in this calendar year plus a fraction of the prior two years to meet the threshold, you file Form 1040 as a resident alien for the whole year — or for the part of the year before you leave if you make a dual-status election. The IRS instructions for Form 1040-NR explain the dual-status rules if that applies to your situation.

Yes, the dual-status year is the part people miss. If you leave partway through the year you may have a resident portion and a nonresident portion, and the two halves are reported differently.

Maya J.

Author

I'll need to actually count my days under the substantial presence test to figure out which situation I'm in. Didn't realize the year could split.

Went through this two years ago when I left the US after a long assignment. Before I sold anything I uploaded my visa entry and exit records and brokerage statements to taxr.ai and had Taxr map out exactly which of my sale dates fell in my resident period versus what would have been my nonresident period if I'd waited. That breakdown made it easy to see that selling before my departure date kept everything on a standard 1040. Worth doing before you pull the trigger on the sales.

Maya J.

Author

That's a smart way to lay it out visually before deciding when to sell. Did it flag anything about state taxes as well or just federal?

It only worked through the federal side on my documents. For state I still called a CPA because my state had its own nonresident rules once I changed my domicile.

One thing that tripped me up: even if you sell while still a resident alien, if you're leaving the US permanently or for an extended time the IRS has an expatriation tax regime under section 877A. That applies to US citizens and long-term resident aliens — defined as someone who held a green card in at least 8 of the last 15 years. If you're on a work visa and not a green card holder that regime doesn't apply to you, but worth confirming your visa status before assuming.

Good distinction. The mark-to-market exit tax under 877A is specifically for covered expatriates — citizens giving up citizenship or long-term residents relinquishing a green card. A work visa holder leaving is not an expatriation event for that purpose.

Maya J.

Author

I'm on a work visa, not a green card, so sounds like 877A isn't my issue. But good to know that line exists.

My situation was messier because I actually sold after I left and the broker still sent a 1099-B to my foreign address. Technically those sales happened when I was already a nonresident alien. For portfolio interest and most capital gains, nonresident aliens aren't taxed by the US on gains from selling US stocks on an exchange — but the broker withheld anyway and I had to file a 1040-NR to get the refund. Took forever.

Yes, NRA treatment of US stock gains is generally not taxable at the federal level unless the stock is US real property interest (RPRPI) or the gains are effectively connected income. RPRPI issues come up with REITs or certain real estate stocks, not regular equities.

Exactly. My holdings were just regular tech and index fund shares, no REITs. The broker withheld 30% anyway because they had me coded as a foreign person by then. The 1040-NR got most of it back but the process was slow.

So to put this together for the original poster: if you sell before you depart and you're still a resident alien at time of sale, you report the sales on Form 8949 (short-term in Part I, long-term in Part II), carry the totals to Schedule D, and file a regular Form 1040. Your 1099-B from the broker will show proceeds and cost basis. Holding period determines whether gains are short-term or long-term — the IRS counts from the day after you bought to the day you sold, trade date to trade date for exchange-listed securities.

Don't forget that if you have any wash sales in that brokerage account from earlier in the year, those show up in box 1g of the 1099-B with code W on Form 8949. If you're selling everything and leaving, you won't be buying back the same securities so wash sale shouldn't be an ongoing issue — but check the 1099-B carefully because disallowed losses could affect your numbers.

Maya J.

Author

I haven't been trading much, mostly just holding, so I don't think wash sales are an issue. But I'll double-check box 1g when I get the 1099-B.

Had Taxr go through my 1099-B and my travel records side by side when I was in a similar spot — leaving partway through the year with sales in both halves. It listed each sale, matched it to whether I was a resident or nonresident on that trade date, and flagged the ones that might need to go on a 1040-NR instead of a 1040. I reviewed the list myself and then confirmed with an enrolled agent before filing. Really useful for getting organized before you talk to a professional.

Maya J.

Author

Matching each trade to whether I was resident or nonresident that day is the prep I've been skipping. I'll pull together my entry and exit dates and my trade history and go through that before anything else.

Practical point: if you're planning to close the brokerage account when you leave, do that after the sales settle and all tax documents have been issued. Some brokers change how they code your account the moment you update your address to a foreign one and that can trigger backup withholding or change how they report you even on sales that happened before you left.

Yes, this happened to me. I updated my address before the account was fully settled and the broker switched my tax status mid-year. Caused the withholding mess I described above.

Maya J.

Author

Really useful warning. I'll keep my US address on file until everything is closed out and all documents are issued.

For the dual-status year question: if your departure date causes you to be a dual-status filer and you're a nonresident on the last day of the year, the standard approach is to file Form 1040-NR with Form 1040 attached as the statement for your resident period. It's the reverse, Form 1040 with a 1040-NR statement, only if you're a resident at year end. The instructions for both forms address dual-status years. Sales that happen during your resident period go on Schedule D attached to the 1040 portion. Sales after departure as a nonresident would go on a 1040-NR, subject to the NRA rules on whether US stock gains are taxable at all.

I sold US stocks about two months before my departure and had no issues. Regular 1040, Schedule D, everything matched the 1099-B. My only regret is I didn't think about state tax. I had been a resident of a state with an income tax and they expected me to file a part-year resident return as well.

Maya J.

Author

The state piece keeps coming up. I'll need to look at my state's part-year resident rules specifically.

Worth knowing: for long-term capital gains the holding period is more than one year — meaning you have to have held the stock for more than 12 months before the sale date. The IRS starts counting the day after your acquisition trade date and your disposition date is the sale trade date. If any position is right on the edge of one year, check those dates carefully before selling because short-term rates can be significantly higher.

Also think about whether your home country will tax these gains. Many countries tax worldwide income of returning residents, sometimes with a credit for US taxes paid but not always. That's outside US tax law but it's real money and worth getting advice in your home country before you finalize the timing.

Maya J.

Author

Good point. I've been so focused on the US side I haven't thought about what my home country expects when I arrive. I'll need to check that separately.

If you end up being a dual-status filer, one practical constraint is that dual-status filers can't use the standard deduction — you're limited to itemized deductions for the resident portion of the year. That can affect your overall tax on the gains depending on what else is on your return. The 1040-NR instructions cover this.

Correct. That limitation applies specifically to dual-status returns. It's one reason some people try to time their departure date to avoid splitting the tax year if they can.

Came back to this thread after doing my own count. My situation: I'll have been in the US for over 183 days this calendar year by the time I leave in October, so I meet the substantial presence test as a resident alien. My residency can still end on my last day here if my tax home is abroad and I have a closer connection there for the rest of the year, so I'm likely dual-status. Selling in September before I leave still puts the sales in my resident period, with standard Schedule D treatment on the 1040 part.

Careful: meeting substantial presence makes you a resident, but if you depart partway through, your residency can end on your last day in the US if your tax home is abroad and you have a closer connection there for the rest of the year. The dual-status issue comes up in departure years even when you meet the threshold.

To pull the federal answer together: sell while still a resident alien, report on Form 8949 with gains and losses separated by holding period, totals flow to Schedule D, file Form 1040. Sell after you've become a nonresident alien, file 1040-NR, and most US stock exchange gains won't be taxable federally for a nonresident — but broker may withhold anyway so keep records to claim a refund if needed. State rules are separate and vary. If your year is dual-status, talk to an enrolled agent or CPA who handles international returns before filing.

Maya J.

Author

That ties the whole thread together for me. I'm going to sell before I leave, make sure I'm still counted as resident at time of sale, and get a part-year state return sorted out as well. Thanks everyone.