You hear about it all the time, everyone knows it, estimating is hard. I think my biggest problem is my optimism. In reality, estimating is something you learn by doing. You'll miss the mark a few times. The key is to learn from those misses. It's like tracer bullets, shoot, miss, adjust, adjust, hit! I've definitely gotten better, and here's what works for me.
Assuming the project requirements are correct, I go through the process of building the project in my head. I break everything down into little steps, and I write each of those steps on one line in Evernote. Once I've got all the steps listed, I go over it again and again, sometimes breaking things down into smaller steps. Don't forget to account for meetings and revisions, those add up. Now I start estimating the individual pieces. Add it all up and you have your estimate.
Hold up, we're not finished. Unless you've done this before, that was just a tracer bullet. The key to learning how to estimate is learning from your mistakes. Once I start working on the project, I track my time to each individual step. Once I'm finished with the step, I write my actual time next to my estimated time. At the end of the project, I can see how far I missed the mark on each individual step. You may have to account for unusual circumstances that may attribute to the difference, but regardless, you will have a much better understanding of how long it takes you to do things. I also find that I forget steps during the estimation process that I discover during the build. Write these new steps out and put your actual time next it. You can refer to past estimates for new projects and include those missed steps.
Granted, every project is different and you'll be tasked with doing things you've never done before. You'll have to fire a few tracer bullets, but if you measure your misses and make adjustments, you'll get much closer to the target.
How far did you miss the mark? Measure it, adjust, and fire a more accurate estimate!