When doing estimates, I often add a "fudge factor" of around to a third to a half more time than originally estimated. For example, if I estimate a project or task to take 100 hours (without the "fudge factor"), I'll turn in an estimate of 130 to 150 hours, depending on how far off I think my first-pass estimate could be.
Be realistic about your estimates when estimating individual tasks in a project. If nothing goes wrong, it will take x amount of hours, but we all know that something always does go wrong, or not according to plan. That's why you need to add in that "fudge factor."
One of the best things you can do to get better at estimating is compare your estimate to the actual time spent. That means keeping track of your time and hanging onto historical data. Estimating is difficult, but with practice, you can get better!