I think this kind of thing comes only with experience. Large amounts of experience.
There are simply too many factors to consider. The team, the client, the project.
I usually follow this rule: take the worst case scenario estimate and then double it :)