Oftentimes, when a knitter first has a go at making socks, their initial pair comes out too big. In seeking to address this, the impulse tends to be, to reduce the number of cast-on stitches. Because fewer stitches equals a smaller sock, right? It also makes for less knitting, faster knitting! Not to mention it is more economical on the yarn meterage.
Unfortunately, reducing stitch count doesn't always solve the saggy sock problem. The smaller-sized sock might start out fine. But it will quickly get stretched out with wear, and again start to sag and slide off.
This is because, more often than not, the real problem is the density of the sock's fabric - i.e. gauge. If a sock is too drapey, that drape - no matter how few stitches you cast on - will result in the fabric stretching and sagging.
In order to fit well - and, more importantly, to retain their fit with repeated wear - socks must be knitted densely; at a considerably tighter gauge than a garment.
To give you some concrete figures in relation to my own knitting:
For fingering-weight yarn (400m/100g), my typical garment gauge is 28-30 stitches per 10cm.
My typical sock gauge is 35-37 stitches per 10cm.
As far as how many stitches to cast on, that translates to around 64 stitches for a typical adult female foot (assuming, again, fingering-weight yarn, and fairly 'vanilla' socks with no colourwork, chevron, slip stitch, cables, or other motifs that call for modifications to stitch count).
So let's take a scenario where you've tried knitting a basic 64 stitch sock but the result is too big. Take a ruler to it and check: are you getting gauge (of at least 35 stitches per 10cm)? If not, next time keep the same stitch count but go down in needle size.
Now let's take another scenario, where your go-to stitch count for socks is 56. Your finished socks start out the correct size for you, but stretch out with wear. What you need to do here is go up in stitch count to 64, and at the same time go down in needle size to meet gauge. The result will be the same size as your current socks, without the sagging.
And of course as far as what size needles to use, that will depend on your individual tension. Being a loose knitter myself, I knit fingering-weight socks on 2.00mm needles. Others can get the proper gauge on 2.50mms, while others need to go sub-2.00mm! Remember that needle size is only a means to get the correct gauge, so use whatever size works for you to achieve that.
I receive a lot of questions about saggy socks, so hopefully this is helpful. Most basic sock patterns offer sizes in increments of 8 cast-on stitches, so finding patterns with a 64 stitch count (including, ahem, my own!) should not be a problem.
Knitting socks at a tight gauge will not only prevent them from growing saggy with wear; it will also make them last longer. But that is a topic for another post!