Obviously the answer to the question in my headline is "As many as you can afford." But for most of us there's an upper limit to how many pairs of headphones we want to keep around. One way to limit and hone down your headphone collection is to look at headphones from a usability perspective and view them as sonic tools designed to serve different purposes and environments. That pair of earphones that sounds great when listening at home in a quiet room can sound awful on the crosstown bus. What's the difference - isolation, or the lack of isolation.
And what is isolation as it applies to headphones? For those who are partial to numbers a headphone's ability to isolate or reduce the noise levels from the outside environment can be measured in dBs. No isolation (such as you would get from an open-enclosure headphone) would deliver 0 dBs, while the very best in-ear monitors can deliver between 25 and 30 dB of isolation.
So why not just use headphones with closed enclosures (or in-ears) with maximum isolation and be done with it - the best isolation solution wins? Because, when you enclose or seal an earphone you now have problems with enclosure resonances and bass loss if your earphones not properly sealed (and sometimes too much bass energy inside your ear canals when they are). Also sealed or enclosed earphones tend to have smaller perceived soundstages. So, although a sealed headphone will solve your isolation problems it comes with its own set of sonic issues.
What to do? The solution is to have at least two pairs of earphones - a sealed or well-isolated pair for public and noisy environments, and an open pair for quiet private spaces. And what about "noise-cancelling" headphones in lieu of highly isolating ones? My personal preference is for isolation instead of cancellation - isolation doesn't depend on batteries, and I feel that blocking the outside sounds from reaching your ears is a better and more complete solution than merely inverting the outside noise's phase so it cancels itself out (which is how noise cancellation works).
If I could only have three pairs of headphones my third pair, after one highly-isolating and one open-enclosure pair, would be an "in-between" pair that provided some isolation but not complete isolation. I use these types of earphones in public spaces where I need to have some degree of situational awareness, such as while waiting in an airline terminal. It's a drag to wait for a plane only to discover at the last minute it's moved to a new gate, but you didn't hear the announcement...
You've probably noticed that I haven't named any names as far as which earphones in each category I would recommend. That is intentional. The final (and perhaps most important) deciding factor in any earphone choice is how well it fits. Without an optimal fit not only won't a headphone perform at its best, but you won't be able to wear your earphones for long periods comfortably. I've owned and used the Etymotic ER-4 in ears as my go-to high-isolation in-ears for many years, but I know that some people can't stand the way they fit, deep inside your ear canals. But for me the Etymotics deliver greater isolation than some of my custom-molded in-ears. This is only one example of how individualized the fit and feel of an earphone can be.
So, there you have it - own three pairs of earphones and your personal transducer world will be completely covered for all situations. You folks who own thirty different pairs of in-ears or open enclosure headphones, get with the program! The secret is that you only need three pairs, honest...but they need to be three different types of earphones...