If you want to knit socks that fit, you need to understand a concept called negative ease. Ease is how tightly (or loosely) an item of clothing fits: positive ease means that the garment is larger than the body wearing it, and negative ease means that it is a little smaller. It is important to knit socks with negative ease, because when we wear them, we want them to fit snuggly to the foot and not fall down.
As a general rule, a sock should have about 10% negative ease in the circumference, and (because knitting stretches in both directions), about 1 cm negative ease in the foot. Let's work through a practical example together to demonstrate:
measured circumference of the ankle is 9".
circumference of sock leg == 9" x 90% == 8.1".
gauge of leg stitch pattern == 30 sts per 4" == 7.5 stitches per 1".
8.1" x 7.5 stitches per inch == 60.75 stitches
Therefore, when looking at a pattern, we should look for the size that is closest to 60 stitches to get a sock that fits well: a few stitches above or below that number won't make a huge difference to the fit, but more than about 4 stitches on either side and the fit may be too snug to feel comfy or too lose to stay up.
Making sure that you choose the right size in a pattern can make the difference between your favourite pair of socks and a disappointing project that you end up gifting to someone you don't really like.