Do foreigners have to pay capital gains tax in the US?

Do foreigners have to pay capital gains tax on US stocks? I'm on an F-1 visa, been here about 14 months, sold some shares through a US brokerage and got a 1099-B. My broker withheld nothing and said it's up to me to figure out my tax situation. I checked the IRS site but keep going in circles between the nonresident alien pages and the resident alien pages. I don't know which one I even am. The shares were in a US company, bought and sold entirely through my US brokerage account. No real estate involved, just regular stock. I already filed an FBAR for a foreign account separately. Do I owe capital gains tax on these stock sales, and does it matter whether the gain is short-term or long-term?

31 comments

The first thing you have to settle is whether you are a resident alien or a nonresident alien for tax purposes, because the answer to your actual question depends entirely on that. It is not the same as your immigration status. The IRS uses the substantial presence test: count the days you were physically in the US in the current year and the two prior years using a weighted formula. If you pass the threshold you are a resident alien and file Form 1040 like a US citizen — capital gains go on Form 8949 and Schedule D. If you don't pass, you are a nonresident alien and file Form 1040-NR. The rules are very different under 1040-NR.

Diego J.

Author

Current step: figuring out the substantial presence test. I've been here since late in my second year of F-1, so I need to count carefully. Is there an exemption period for F-1 students?

Yes — F-1 students are generally exempt from counting days for the substantial presence test for 5 calendar years. So if you're still within those 5 years you're almost certainly a nonresident alien and should file 1040-NR, not 1040. That changes everything about how your capital gains are taxed.

My situation was similar — nonresident on a visa, sold US stocks, got a 1099-B and had no idea what applied to me. I uploaded the 1099-B and my visa details to taxr.ai and it walked through each line of the form against the 1040-NR rules, flagged where my broker had used the wrong withholding assumptions, and drafted a summary of what needed to go where. Helped me see the full picture before I brought it to a CPA. The key thing it surfaced: for a nonresident alien, most capital gains on the sale of US stocks are NOT subject to US tax unless you were present in the US for 183 days or more in the tax year — a separate 183-day rule that only applies to nonresidents on 1040-NR, different from the substantial presence test.

Diego J.

Author

Next step: checking how many days I was actually in the US during the tax year itself. If that 183-day count is what triggers tax for nonresidents, I need that number before anything else.

Worth knowing that the 183-day count for the 1040-NR capital gains rule is a straight count of days in the calendar year — no weighting like the substantial presence test. If you're under 183 days you generally owe nothing on those stock gains to the US.

Resident alien here — came in on a work visa years ago, passed the substantial presence test in my third year. For me capital gains work exactly like a US citizen. Short-term gains (held 1 year or less) are ordinary income. Long-term gains (held more than 1 year) get the preferential rates. The holding period starts the day after you buy, on trade date, and ends on the trade date you sell. All of it goes on Form 8949 and flows to Schedule D. My broker's 1099-B had everything I needed for column (d) proceeds and column (e) basis.

There's also a treaty angle worth raising. Some countries have tax treaties with the US that change the default rules for nonresident aliens — could reduce or eliminate withholding on certain income. Capital gains treatment under a treaty depends on the specific treaty language. The IRS has a table of treaties and you'd look at the capital gains article for your country. If a treaty applies you'd claim it on Form 1040-NR using a specific exemption code. Not every country has a favorable capital gains article though.

Diego J.

Author

Current step: looking up whether my home country has a tax treaty with the US. I hadn't thought about this angle at all.

When I was sorting out my own nonresident filing after selling ETF shares, I ran my 1099-B and my passport entry/exit stamps through Taxr and it built out the day count for me and compared it against the 1040-NR thresholds. Really useful to have something check the numbers before I handed everything to an enrolled agent. The agent confirmed the analysis was right. Bottom line from my situation: under 183 days in the tax year as a nonresident, the gains on those stock sales were not taxable in the US, and nothing went on the 1040-NR for them.

That tracks with what I've read in Publication 519. The nonresident capital gains rule really does hinge on that single-year day count, not the weighted formula.

Diego J.

Author

Next step: I'm pulling my entry and exit dates now. Looks like I was under 183 days in the tax year. If that holds up I may not owe anything on these gains.

One thing to be careful about: even if the gains aren't taxable in the US, you might still need to file a 1040-NR depending on whether you had other US-source income. If you had wages, scholarships, or other US-sourced amounts above the filing threshold for nonresidents, you file 1040-NR and just don't report the exempt capital gains. Don't skip the filing just because the stock gains are zero-taxed.

Diego J.

Author

Current step: I do have a small US stipend from my program. So I probably need to file 1040-NR regardless. Good to know the gains would just be omitted rather than included.

Went through this two years ago as an F-1. The F-1 exempt-individual rule means the five calendar years I was here on F-1 didn't count toward substantial presence. Filed 1040-NR both years. Capital gains from my brokerage — all under 183 days in the year — were not reported as income. My broker sent a 1099-B anyway and I just kept it for my records. No issue.

If you end up being classified as a resident alien after all, the Schedule D and Form 8949 workflow is the same as for any US filer. Short-term goes in Part I of 8949, long-term in Part II. Your broker should have checked box A or D on the 1099-B to tell you whether basis was reported to the IRS. If it was and there are no adjustments needed, those transactions can go straight to Schedule D line 1a or 8a under Exception 1 without itemizing each one on 8949.

Exactly right on the exception. Saves a lot of rows on 8949 when you have a lot of transactions with no adjustments and covered basis.

If any of your holdings were crypto rather than traditional stock, look at the IRS digital assets page too. The reporting rules differ and there's a new 1099-DA form that brokers are starting to use. For traditional stock the 1099-B is still the document.

Does the type of US company matter? Like does it change anything if the stock is in a partnership taxed as a pass-through versus a regular corporation?

For a nonresident alien it can matter a lot. A partnership with US trade or business income creates effectively connected income for the partners regardless of residency, which can pull the gains into US taxation even under 183 days. That's a different analysis than selling shares of a regular C-corp on a stock exchange. If the investment is in a publicly traded partnership or similar structure, the analysis is more complex and a CPA or enrolled agent familiar with nonresident rules is worth consulting.

Current step: mine are regular exchange-listed stocks so it sounds like the standard nonresident analysis applies. Good to know the partnership issue exists though.

I'd also flag that if you later transition to resident alien status — say you get a green card or pass the substantial presence test after the F-1 exempt years — your holding period and basis in shares you bought as a nonresident carry over. The character of gain (short vs long-term) is based on total time held. So shares bought years ago as a nonresident still get credit for that holding time once you're a resident.

Diego J.

Author

That's actually useful forward-looking info. I may switch status in a couple years and hadn't thought about how the existing shares would be treated then.

My accountant made me aware that some nonresident aliens are subject to a flat rate on US-source capital gains that ARE taxable — the 1040-NR instructions and Publication 519 explain that a flat 30% (or lower treaty) rate applies to that net gain no matter whether it was short-term or long-term. The rates and thresholds aren't the same as the resident alien brackets. Worth reading the 1040-NR instructions carefully rather than assuming the same numbers apply.

To summarize the path for OP's situation as I read it: 1. Determine resident vs nonresident using the substantial presence test plus the F-1 exempt-individual rule. 2. If nonresident: count actual days in the tax year. Under 183 — gains on US stock sales generally not taxable. 3. Check for a tax treaty with your home country. 4. File 1040-NR if you have other US-source income regardless. 5. Keep the 1099-B; your broker reports it even if you owe nothing on it.

Diego J.

Author

Current step: this is the clearest path I've seen laid out. I'm at step 2 and it's looking like under 183 days. Will confirm and then figure out the 1040-NR for the stipend income.

Publication 519 is the IRS publication specifically for US tax guide for aliens. It covers the substantial presence test, the exempt individuals list, the 183-day rule for nonresident capital gains, and the 1040-NR filing requirements. Worth reading straight through before you file. It's on irs.gov under publications.

Agreed — Pub 519 is the right starting point. The substantial presence test section lays out exactly which visa categories are exempt and for how many years.

Real estate is a whole separate situation just so it's clear. The OP said no real estate, but for anyone reading: gains from US real property by a nonresident are always effectively connected income and always taxable in the US — FIRPTA rules apply and the buyer often withholds. That's completely different from selling stock on an exchange.

Also worth noting: if losses exceeded gains on the 1040-NR, the capital loss deduction rules for nonresident aliens are more limited than for residents. I'd check the 1040-NR instructions on that before assuming you can carry forward losses the same way a resident would.

Good point. The loss carryover rules under 1040-NR are not the same. For residents the capital loss carryover worksheet in Publication 550 or the Schedule D instructions handles it, but nonresidents need to follow the 1040-NR specific rules which are narrower.