If you spend enough days in the US to meet the Substantial Presence Test but have not been a lawful permanent resident and have a closer connection to a foreign country, you may be able to avoid US tax resident status by filing Form 8840. To qualify, you must have been present in the US for fewer than 183 days in the current year, maintain a tax home in a foreign country during the year, and have a closer connection to that country than to the US. The IRS looks at factors like where your permanent home is, where your family lives, where your personal belongings are, and which country's driver's license and voter registration you hold. Form 8840 is filed with your US tax return by the due date, including extensions, and filing it puts the IRS on notice that you're claiming the exception. If you don't file Form 8840 in a year when you qualify for the exception, you may be treated as a US resident for that year by default, which could significantly increase your US tax obligations.