For a foreign citizen to be considered a U.S. resident for tax purposes, he has to stay in the country over 31 days in the year or 121 days in this year and the previous 2 years. This rule is applied under the substantial presence test.
Another rule is the closer connection test under which someone who doesn't spend more then 183 days in the U.S. and his principal residence and business or trade back home is not considered a U.S. resident in the eyes of the IRS.
Foreign citizens exempt from the substantial presence test are:
There are some rules that apply when it comes to counting the number of days for the substance test; count full days for this year and then count the days in the preceding year as only 1/3 of the day (3 days equal one full day.) Then count the days in the second preceding year as only 1/6 of the day, (6 days equal one full day.)