Ok, I've gone on at length about why you have to check (and match gauge). And now to answer the first question: How? And what do you do about it?
At its most basic, you swatch to make sure you're using the size of needles that's right for you. That's all.
Step 1. Knit a swatch.
How many sts and rows are you supposed to get? Take that number and multiply it by 1.5 to 2. E.g. for 18 sts/24 rows, cast on about 30 sts and knit until the piece is about 6 inches long. Use the needles recommended in the pattern to start. 'Recommended' is the key word here - these are the needles that the designer used to get gauge, but you might knit looser or tighter. Work in the pattern stitch specified; most often stockinette stitch.
Step 2. Wash the swatch.
Oh yes. Are you going to ever wash the garment? If so, you need to wash your swatch. Many fabrics can change quite radically with washing: superwash wool stretches out a fair bit, cottons can shrink up and change shape; linens and hemps relax. If your garment fits you before you wash it, it's quite likely it won't fit after you've washed it.
(This means that the garment that comes off your needles might not fit until you wash it the first time. Cool by me, since you should wash the pieces before you sew them together anyway.)
Oh yeah, and let it dry before you measure it. Like, overnight.
Step 3. Measure the swatch.
Fractions matter very much.
Step 4. Consider your plan of action
Have you matched gauge? Raise a glass! Eat a cupcake! Give yourself a round of applause! You're ready to start knitting.
And by "matching gauge" here I mean PRECISELY the right number of sts in 4 inches, and pretty much the right number of rows in 4 inches. Dirty secret: there's a bit of room for fudge in rows - if you're within about 10% of the required number (e.g. 28 instead of 26), you'll be fine for most purposes.
Are you off? By how much? If you're within about 10-15%, then a needle change should get you where you need to be. If you're off by more than about 10-15%, chances are you're going to need to change yarn. Changing the gauge of a fabric that much is likely to affect the fabric too much.
Too many stitches?
You're knitting too tight. (You're fitting more sts into four inches than you should have, therefore they are too small.) Move up a needle size and start again.
Too few stitches?
You're knitting too loose. (You're fitting fewer sts into four inches than you should have, therefore they are too big.) Move down a needle size and start again.
Frequently asked questions:
OMG. Are you telling me I have to do this all over again? Are you out of your mind?
Frankly, your gauge should never be a surprise. That is, I start measuring once I've got an inch or two of my swatch worked to get a sense of whether I'm even in the vicinity. If I'm not; I'll stop right there and restart. I've even been known to wash a half-knitted swatch on the needles.
Will I run out of yarn?
Likely not, but hang on to your swatches and if you need the yarn as you get near the end of the project, undo them.
Isn't this a lot of work?
Well, it might take up an evening, but it's significantly less work than knitting a sweater that doesn't fit. (See my post about me being unsympathetic on this point... )