The best thing you can do if it happens to you is to try to stay calm and remember the following.
1. Negotiate severance. Your company will probably offer you some amount of severance payment. This is often negotiable – especially if your company has special interest in getting you to sign a "general release," the standard agreement that in exchange for severance payments releases the company from any future legal claims stemming from your employment there. You won't always be successful in trying to negotiate more, but sometimes you will and it never hurts to try.
2. Ask about logistics, like how long your health insurance coverage will last and whether your accrued vacation time will be paid out. Some of these logistics may be negotiable as well. For instance, you might try to get several additional months of health coverage.
3. Negotiate what will be said about why you left and your performance. You want to know precisely what your employers will say about you to any reference-checkers who may contact them. This statement itself is often negotiable, and now is the time to bring it up.
4. Collect as much information about the circumstances of the layoff as you can. While you don't want to push the company for information it's not going to release, it's helpful to understand as much as you can about the size of the layoff and the reasons for your position being part of it. In future job interviews, it will be helpful to be able to explain that, for instance, you were part of 200 positions that were cut, or that the company was eliminating your job function entirely.
5. Be gracious with colleagues. While it's obviously worse for you, layoffs are hard on the people left behind too, and co-workers often won't be sure of what to say. As with a death, some people aren't sure what to say and so avoid the topic altogether. By being gracious yourself and not bad-mouthing the company or otherwise putting co-workers in an awkward position, you'll make it easier for them to maintain the relationship with you and reach out to you in the future with job leads and other overtures. Speaking of which…
6. Ask your manager and former colleagues for help finding a new job. Don't be shy about doing this or think that it will be too uncomfortable to ask. It's normal to ask, and many laid-off people have found their next job by making precisely this request.
7. Don't do anything rash, particularly in anger. While it might be momentarily satisfying to tell off your boss on the way out the door, or to bad-mouth the company to clients, resist the impulse. You'll harm your own reputation at exactly the time you need it in good shape for your job search.
8. File for unemployment immediately. Even if you think your job search won't take long or your savings can sustain you, file for unemployment – because you can't predict how long it will take to find a new position (particularly in this market). And file right away, because it can take a few weeks for benefits to kick in.
Alison Green writes the popular Ask a Manager blog, where she dispenses advice on career, job search, and management issues. She's also the co-author of Managing to Change the World: The Nonprofit Manager's Guide to Getting Results, and former chief of staff of a successful nonprofit organization, where she oversaw day-to-day staff management, hiring, firing, and employee development.