IRC 7701 for determination of Tax Residency
In order to determine the residential status under Internal Revenue Code , one needs to consult Revenue Code (26 US Code ) 7701 which is as under:
(b) Definition of resident alien and nonresident alien
(1) In general For purposes of this title (other than subtitle B)—
(A) Resident alienAn alien individual shall be treated as a resident of the United States with respect to any calendar year if (and only if) such individual meets the requirements of clause (i), (ii), or (iii):
(i) Lawfully admitted for permanent residence
Such individual is a lawful permanent resident of the United States at any time during such calendar year.
(ii) Substantial presence test
Such individual meets the substantial presence test of paragraph (3).
(iii) First year election
Such individual makes the election provided in paragraph (4).
(B) Nonresident alien
An individual is a nonresident alien if such individual is neither a citizen of the United States nor a resident of the United States (within the meaning of subparagraph (A)).
But reading it and understanding the legal jargon is quite complex. A post to explain the rules of tax residency under US tax law and given below is the calculator for finding out your tax residency. You can read IRS guide on residency
Calculator for Finding Tax Residency Under US Law?