U.S. tax law categorizes people as resident aliens or nonresident aliens for tax purposes only, which is not necessarily the same as residency according to immigration law. Resident aliens for tax purposes follow the same rules as U.S. citizens for taxation. For a nonresident alien for tax purposes there are special taxation rules that apply. There are also special rules that apply specifically to F-1 students, J-1 students and scholars and H-1 employees who are nonresident aliens for tax purposes. These tax statuses are significant because filing under the incorrect tax designation may result in taxes owed back to the government. So, it is important to know your status to file correctly. Nonresident aliens for tax purposes are taxed on U.S. source income.
The U.S. Department of Treasury Internal Revenue Service Publication 519 explains the rules used to determine tax residency for those who are not U.S. citizens.