I do not think that this is a question that can be easily answered by most of us and when I ask it I do so in the context of such circumstances as: As a president of an organization or company, as a long time employee, as the head of any conglomerate, and so on.
For me, I believe that it is extremely important to be able to gage when is the best time. There may not be a best time but I am sure that if we take certain variables into consideration then stepping down could become less of a painful ordeal for most of us. These are my respectful suggestions.
Never overstay your welcome. That is, try not to stay too long in your position and when you hear those whispers from those around you or close to you that you should be thinking of stepping down, then pay close attention to them.
The minute you feel that you are no longer mentally able to function at your best or close to it, then it may be time for you to step down. If you feel that the job no longer satisfies your desires or your passions, then it may be time for you to call it a day. Or if you feel that your satisfaction level has dropped considerably or that you really would prefer to be elsewhere, then the time may have come for you to step down.
These are just my personal thoughts and I am sure that you would have your own suggestions to add.