If you have an expired non-immigrant visa stamp in your passport (for example F or J) and you have a valid I-94 card or I-94 print out from the I94 website stating your current status, your visa will be considered valid when you re-enter the US from Canada or Mexico as long as ALL of the requirements below.
For automatic revalidation to apply to you, you must be careful to keep your I-94 card or I-94 print out from the I94 website when leaving the US. When you re-enter the US, present your I-94 card or I-94 print out along with your valid passport, expired visa, and your valid immigration document (I-20, DS-2019 or I-797 in the case of someone in H1B or O visa status).
The automatic revalidation will also work for someone who originally entered the US in one non-immigrant status (such as F1) and has since changed to another non-immigrant status (such as H1B). The expired F1 visa will be considered to be valid and changed to H1B for the entry from Canada or Mexico. Those in H1B status should also carry the original I-797 approval notice while traveling which you can borrow from the ISSO.
For those in F or J status (but NOT any other status), the automatic revalidation also works for visits of less than 30 days to the adjacent islands.**
If you are a "special registrant" (you would have been told when you entered the US that you were being "special registered" as part of the "NSEERS" program), then you must leave the US for Canada or Mexico through a designated port of departure. You must register your departure with the port inspectors. At that time, state to the inspectors that you intend to re-enter using automatic revalidation.