You will be considered a United States resident for tax purposes if you meet the substantial presence test for the calendar year. To meet this test, you must be physically present in the United States (U.S.) on at least:

Example:
You were physically present in the U.S. on 120 days in each of the years 2019, 2020 and 2021. To determine if you meet the substantial presence test for 2021, count the full 120 days of presence in 2021, 40 days in 2020 (1/3 of 120), and 20 days in 2019 (1/6 of 120). Since the total for the 3-year period is 180 days, you are not considered a resident under the substantial presence test: for 2021.

Days of Presence in the United States

You are treated as present in the U.S. on any day you are physically present in the country, at any time during the day. However, there are exceptions to this rule. Do not count the following as days of presence in the U.S. for the substantial presence test:

The term United States (U.S.) includes the following areas:

Exempt Individual

Do not count days for which you are an exempt individual. The term “exempt individual” does not refer to someone exempt from U.S. tax, but to anyone in the following categories:

Closer Connection Exception to the Substantial Presence Test

Even if you met the substantial presence test you can still be treated as a nonresident of the United States for U.S. tax purposes if you qualify for one of the following exceptions:

Determining an Individual’s Tax Residency Status

If you are not a U.S. citizen, you are considered a nonresident of the United States for U.S. tax purposes unless you meet one of two tests. You are a resident  of the United States for tax purposes if you meet either the green card test or the substantial presence test for the calendar year (January 1 – December 31).
In some cases, you are allowed to make elections which override the green card test and the substantial presence test, as follows:

You can be both a nonresident and a resident for U.S. tax purposes during the same tax year. This usually occurs in the year you arrive or depart from the United States. If so, you need to file a dual-status income tax return.