A tax treaty is an agreement between the US and another country about who taxes what. The US has treaties with many countries, but not all, and every treaty is different.
Avoid double tax: so the same income is not fully taxed in both countries.
Exempt some income for students, teachers or researchers, for a limited time or up to a dollar amount.
Lower the tax rate on things like dividends, interest or pensions.
Example: some treaties let a student earn a certain amount of wages each year without US federal income tax, for a few years. Others exempt scholarship money. Some countries have no student benefit at all.
How to check your country
Go to irs.gov and search "Tax treaties A to Z". Find your country.
Open the Tax Treaty Tables on irs.gov. Table 1 shows rates; Table 2 shows wages and personal services, including students and teachers.
Read Publication 519, appendices A (students) and B (teachers and researchers). They list the countries and the conditions.
Note the conditions: how many years, which income, the maximum amount, and whether the benefit stops if you stay longer than allowed.
During the year (wages): give your employer Form 8233 with the treaty article, so less tax is taken from your paycheck. Your employer may also ask for a statement from you.
On your tax return: claim it on Form 1040-NR. Many nonresident tax tools from schools fill this in for you.
Scholarships: your school may ask for Form W-8BEN to apply a treaty rate.
After you become a resident for tax
Usually, treaties stop giving you these benefits once you are a resident for tax. But some treaties keep certain student or researcher benefits even after you become a resident. If you use one, you may need to attach Form 8833 to your return. Check your treaty article or ask a tax professional.
Many states do not follow federal tax treaties. Income exempt from federal tax may still be taxed by your state. This differs by state; see In your state below.
Assuming your friend's treaty benefit applies to you. Benefits depend on your country of tax residence before you came.
Forgetting to give your employer Form 8233, then paying too much tax all year.
Claiming a teacher benefit after the treaty's time limit has passed.