Making a gauge swatch is simple and allows you to be sure that the pattern you're about to knit is going to end up sized the way it claims. You might notice when you get a pattern, that there's a gauge listed at the top of it. It might read something like, "18 sts and 24 rows = 4 in. (10 cm) in St st." This means that you should fit 18 stitches across a row and 24 rows in a 4" x 4" knitted area, knitted in the Stockinette Stitch (knit on right side, purl on wrong side.)
To make a gauge swatch, knit a section that is at least 4" wide and at least 4" long. Afterwards, take your stitches off of the needle and lay flat, making sure that you aren't stretching the swatch. Lay a ruler or tape measure next to the piece and place a pin where the measurement starts and ends. Patterns can call for 1", 2", 4" or any other measurement, so it will depend on what you're trying to match up to.
Now count how many of your stitches fit in the measurement. If you're getting a fraction of a stitch in there but not the whole thing, make sure you note that. This makes a difference, especially if you're knitting a large item! It can be a difference of a sweater ending up a few inches too long or short, for example, so don't round up or down to the nearest inch.
The example in the above photo shows 9 ½ stitches in 2 inches. In this case, the gauge is read 2"=9 ½ stitches and 13 rows (see image below for rows). If you're writing your own pattern, then you probably will want to resize your gauge to a larger or smaller size to accomodate whole stitches. For example, 2" might be 9 ½ stitches, but 4 inches would be 19 stitches and 26 rows.
If your swatch is too big, you would need to use smaller needles, and if too small, use larger ones, and check the gauge again. This is because some people simply knit tighter or looser than others. It can also happen if you're using a different yarn than what is called for.