knitting without a pattern

I haven’t knitted for many years so am a bit rusty but want to try again. I’m knitting a cosy to fit a coffee-pot. I’ve measured the circumference, but the problem is that the finished article may end up wider than it looks on the cast-on row. Is there a sure way of getting the number of stitches right when casting on, to arrive at the right width? thanks to whoever can answer this!

Knowing your gauge with a swatch should get close, but other than trial and error I don’t know of a reliable way to get it right all the time.
I do no pattern sweaters, socks and hats. Now that I have a collection of errors I can count off those and adjust for differences. But it’s usually knit a little, try it on and rip it out and restart.
If you knit a little and try it, check your gauge before ripping, or pin it and count how many stitches there should be. That should have the re-do correct.

I’ve never done a knit to fit cozy (dust cover for me). I find crochet easier for on the fly shaping.