Depends on your winrate and what your acceptable risk of ruin is. 20 buy-ins is usally the absolute minimum standard rule.
I like Harrington's advice on moving up. When you have 150% for the next level, move up. So if you start with 20 buyins at $25nl ($500) move up to $50 when you have 30 buyins for that level ($1500).
Then if you lose 1/2 your new roll, drop back down ($750). In this way even if you lose at the new level, you got experience, now have more money in your roll from where you started, drop back down to your old level likely as a better player, and repeat the process.
Of course for a losing player, there's no bankroll management strategy that will work. They'll always go broke no matter what precautions they take.