Nonresident and Dual-status Aliens
It's easy to tell if you're a nonresident alien. If you don't meet any of the criteria for being a resident alien, then you're a nonresident alien. It's also possible for your status to shift in the middle of the year, which could result in you being a dual-status alien. But before we get into the tax part, we have to figure out which parts of the year you're a dual-status alien.
Dual status depends on which kind of resident alien status you have: lawful permanent resident or substantial presence. In the case of LPR, your term as a resident alien begins the first day you're in the U.S. with your green card. It ends the day you terminate your green card or it is revoked. The remainder of the year, you're considered a nonresident alien, so you will file as a dual-status alien.
Under the substantial presence test, the first day you were in the U.S. is considered the start of your resident alien status, and it ends the date you were last present in the U.S. You can be present for a total of 10 days at either end without triggering (or retriggering) resident alien status.
You might be a resident alien under both LPR and substantial presence. In that case, you continue to be a resident alien as long as either test still applies. In other words, if you terminate your green card but still meet the substantial presence test, you'll still have resident alien status.
There are, of course, exceptions. First, substantial presence will be considered to last through to the end of the calendar year unless you establish a connection to a foreign country, including a tax home in that country, before the end of the year. Also, if you have resident alien status at any point in the year for two consecutive years, you're considered a resident for that entire period. In other words, you can't be a resident, switch to nonresident at the end of the year, start the following year as a nonresident and then switch back to resident. This is known as the non-lapse rule.
Finally, some nations have tax treaties with the U.S. You might be exempt from resident alien status for tax purposes, or there might be other tax regulations you have to follow according to your home country, depending on the specific treaty between your home country and the U.S.
Now that we've established what resident alien status is, it's time to look at what taxes those folks actually owe and whether they need to file a tax return at all.