This question has a lot of answers depending on different things.
How aggressive will you be when it comes to moving down in stakes? If you are willing to drop down a level after 5-10 buy-ins, you are able to play with fewer total buy-ins. Generally, if you're playing with 30 buy-ins at 25NL and are willing to drop down if you hit 20, you're probably fine. You have 10 buy ins at 25NL, 30 buy-ins at 10NL, and then 40 more at 5NL before you're broke. That's 80 buy-ins total, even though you only have 30 at your current stake. The benefit of this is that you can take shots more aggressively (as soon as you hit 30 buy-ins for the next level you can take a shot as long as you are willing to drop back down if you fall below 20 buy-ins for that level).
How reliant are you on your income for your current level of play? If you can't afford to spend time rebuilding at lower levels to get back to where you are, then you need to be more conservative. This goes along with the first point. If you are unwilling or unable to move down for an extended period of time, you need a bigger buffer. This is when you want 50+ buy-ins for the level.
How big is your edge at the stakes and in the games you are playing? If you're beating the level at 12 bb/100, you can survive on a smaller bankroll than if you're beating it at 3 bb/100. If you're not beating the game, you need an infinitely large bankroll.
How aggressively are you willing to push small edges? Are you willing to get your money in when it is likely a 55%/45% edge in your favor? Are you eager to get it in when you're getting 2.5-1 when you have 33% equity? Both these spots are +EV and you should be willing to take them, but they also increase your variance and require a deeper bankroll to handle the swings. If you have a smaller bankroll, you might not want to take advantage of these +EV spots because you risk losing too much of your money. It should be noted that the goal in poker is to always take +EV spots when you get offered them, so playing too safe because you're under-rolled is not a good thing.
Can you reload your account if you lose it all? If so, your real bankroll is deeper than it appears from the money in your account.
What games are you playing? Some have more variance than others. If you're playing limit Omaha/8, you will have much smaller swings than if you're playing deep-stacked No-Limit Omaha with extremely aggressive opponents. If you're playing MTTs, you're going to have much more variance than if you're playing Single Table SNGs. Where 30-50 buy-ins might be fine for sit and gos, 100 or more is probably wise for large multi-table tournaments.
How risk averse are you? How much do you tilt? I find playing with a small bankroll tends to tilt me more when I take a couple beats. I get nervous and play worse. When I know I can take beat after beat and my roll will barely be dented, I find the money bothers me less. This holds true regardless of actual dollar values. If I am playing on a site where I won't reload, I have $50, and I am stuck playing $0.05/$0.10NL, I can get pretty tilted by losing $20. If I am playing $1/$2 live and drop $600, knowing that I have several thousand in my poker bankroll set aside for that game, it barely bothers me. In this case, my losses are small relative to my bankroll, so they hurt less.
Anyway, you need to find the bankroll that works for your situation. When in doubt, more is always better than less.