1. The company-wide 5% layoff. Avoid this by making sure you're not in the bottom 5% of performers, and the people above you know it.
2. The shift-the-legacy-products-to-cheap-countries layoff. Avoid this by making sure you're working on products where you're fixing bugs and making improvements, not just keeping things ticking over.
3. The lay-off-the-entire-department layoff. Avoid this by working in departments that bring in more revenue than they cost, or at least have a good chance of commercial success; and in an area where the company's strategy calls for growth.
4. The lay-off-the-entire-office layoff. Not much you can do about this, except working at the head office, or a very large branch office where important projects are based.
5. The there's-just-no-money / entire-company-goes-out-of-business layoff. Not much you can do about this - but if things are heading in this direction, it's a good time to start sending out resumes and maybe getting the unemployment insurance on your car loan.
Of course these are very risk-averse strategies. I've heard of some people having great success with the opposite strategies - some people say maintaining ancient legacy mainframes for banks is highly profitable. Others have told me the fastest way to get a senior title is a failing organisation, where senior people keep leaving. So none of these are hard-and-fast rules.