My Software Estimation Technique - Jacob Kaplan-Moss
jacobian.org/2021/may/25/my-estimation-technique
What Jamie wrote
Some great wisdom here, but I would amplify even more the uncertainty aspect. Not only do you need to capture and measure that, you also have to realize that if uncertainty is above a certain level there is no possible time estimate. This is why teams tend to use Fibonacci sequences to estimate complexity. As complexity goes up the solution time and cost goes up much more than linearly, and at some point goes parabolic to the moon.
You have to know reasonably well what you are building and how that will happen before any estimation of time is meaningful at all.