Time estimation is hard.
But the times when I've done this well all have a couple things in common:
1.) I received very good and complete requirements for the project. This is important and you should ask the tough questions to make sure that the requirements really are as complete as possible.
2.) I broke the project down into sections, wrote each section on a white board, and then estimated the time for completion for each section individually. I had the rest of my team contribute as I do this so I don't forget anything. This seems so simple, but it works so well. I think it allows you to be more realistic by reducing the possibility of overlooking a part of the project that may be time consuming. If you can write down and plan out the project at a granular level like this it'll help immensely.
During this whole time estimation process you may even gain a better understanding of the project and what needs to be done. That can prevent mistakes, writing & re-writing code, etc. And that's good for everybody.