Anyone with F-1, J-1, M-1 or Q-1 visas entering the country as a nonresident aliens are exempt from paying Social Security and Medicare taxes if they perform the services that they were admitted to United States for. A foreign student under the F-1 visa is not allowed to get a job off campus or engage in a trade unless approved by the college and INS. This is usually made clear on the student's copy of Immigration Form I20, Certificate of Eligibility for Nonimmigrant Student Status, or Form I688B, Employment Authorization Document.
The non-resident aliens with F-2, J-2, M-2, Q-2 or any other types of visas are not exempt from the Social Security and Medicare taxes. However, there is a provision in the law that allows the international student in the employ of the school to claim the exemption if he is a student with the school and performs services for only that school. Some foreign students who don't get the full exemption from the taxes might be able to use this provision to save some money.
If an employer accidentally withholds your taxes, you can ask him for a refund. If he is unable to provide you with one, you can file Form 843 with the IRS, send in a copy of Form W-2, your visa, INS Form I-94, INS Form I-538 (if you have one), and a little note saying that your employer has made a mistake and withheld your taxes and is unable to provide you with a refund.