I got pretty decent at software estimation at my last job.
I would spend an entire day "pre-programming" everything in my head, estimating the length of each little chunk, adding them up, then multiply by ~2.
It worked for me. But I still would never trust the estimates.