The H-1B is a nonimmigrant (temporary) visa that allows certain specialty workers to accept a job with an employer in the United States. You must have a job offer before applying, because your H-1B visa must be sponsored by your employer. However, that doesn't mean you have to stay with the same employer the whole time you are in the United States. If you change your employer, or even find a new employer after a layoff, you can transfer your H-1B visa to the new employer. This relatively new benefit is referred to as H-1B "portability."
Although getting your initial H-1B visa depended on whether the annual "cap" had been reached (that is, whether any visas were left for your use given the high demand and yearly numerical limits), transferring to a new employer is not affected by the visa cap.
To be eligible for an H-1B transfer, the H1B visa holder must:
You can apply for an H-1B transfer more than once. No permission or action from your current (or now previous) employer is required.
If your old employer has already terminated you, you are now out of status, and could be removed from the United States if you have a run-in with immigration authorities. There is no "grace period," contrary to rumor.
On the other hand, if you're able to find a new employer before your old I-94 expires or your old employer revokes your petition, you may be able to bring about an H-1B transfer regardless. Talk to an attorney for a personal analysis and help with this process.
To receive a transfer of your existing H-1B status, your new employer must file a petition on Form I-129, "Petition for a Nonimmigrant Worker," with United States Citizenship and Immigration Services (USCIS). As soon as this has been filed and your new employer has gotten the USCIS receipt notice to prove it, you can start your new job, without waiting for USCIS approval.
Of course, if USCIS ultimately denies the petition, you'll have to stop work and either scramble to get a new job that would qualify you for an H-1B, or leave the country. If your employer wants the certainty of a quick answer, it may want to request premium processing of the petition by paying an additional fee. Premium processing means that the petition will be processed in 15 days (although this doesn't always happen as it should).
There is normally no need for the H-1B visa holder to leave the United States as part of the transfer process. The exception would be if you were laid off from your old job before submitting the petition for a new job, in which case it's possible that USCIS would refuse to extend your old status in order to let you switch to the new one. But you might still be able to apply for the new H-1B by returning to your home country and applying from there -- talk to an attorney for the details of this tricky technical procedure.
When the petition is approved, the new employer will receive a Form I-797 - Notice of Approval from USCIS.
Although an H-1B transfer may sound relatively simple, it is a complex process. The petition can be rejected on various grounds, depending on your personal situation. To avoid a denial, consult with an experienced U.S. immigration attorney.