How to Knit a Gauge Swatch
To knit a gauge swatch, start by checking the pattern you're using for the recommended stitches per inch and rows per inch. Then, knit a 4-inch square, using the recommended needle size, yarn type, and stitch type. Once you're done with your square, take your tape measurer and count how many stitches there are per inch. If there are more than the recommended stitches per inch, you may need to use a bigger pair of needles, and if there are fewer, try a smaller needle.
Knit a gauge swatch. This is a rectangle of knitted fabric used to ensure that your finished garment will be the size you intended. Some patterns require that you wash and block (or shape while damp) your swatch before measuring--this is important because some yarns will change gauge after washing and blocking. Wash the swatch the same way you plan to wash the finished item. Measure the gauge swatch with a ruler. Hold or pin it down flat--don't stretch it or scrunch it. If you cast on the number of stitches specified in the pattern, it should be 4 inches (10.2 cm) on each side, forming an even square (the corners should make right angles, the square shouldn't be crooked). If you cast on a different number of stitches than the number recommended for your pattern gauge, you will need to count your stitches. Count the stitches and rows per inch. In the gauge swatch shown, there are 8 stitches and 6 rows. It can be difficult at first to count the stitches and rows correctly, depending on the type of stitch your knitting the gauge swatch with, but in stockinette stitch, each v when counting across is a stitch and each v counting down is a row. Avoid counting the edges. How many stitches are there per inch? And how many rows per inch? Multiply the number of stitches per one inch by four--then you'll know if you have the correct number of stitches per four inches, as specified in the pattern. Know that if the number of stitches or rows per inch does not match what the pattern specifies, you will probably need to experiment with different needle sizes. If you need more stitches or rows per inch, use smaller needles. If you need less, use bigger needles. Every time you try a new set of needles, knit a new gauge swatch to test them. You can also adjust your gauge by changing the type of yarn you use (thinner yarn if you need more stitches or rows, thicker yarn if you need less) but this is usually inconvenient and should not be necessary if you purchased yarn similar to what was recommended. Check the pattern for the sts. per inch. If possible, also use the rows per inch. Cast on 4 times the sts. per inch for a 4" swatch plus 10 sts. It is more accurate to measure over 4" than only measuring over a 1" piece. Start knitting for five rows of garter stitch. Knit every row. Begin the actual measured swatch knitting keeping the 5 sts. at beg and end of row in garter stitch. On the first right side row, knit the 5 edge stitches and then *k2tog, yo*. Repeat this to denote the size needles you are knitting the swatch with. If the rows per inch is noted knit in pattern for 4 times the count. Namely, 6 rows per inch = 24 rows per 4". Return to garter stitch and knit another 5 rows. Bind off. You now have a completed swatch with garter stitch on all sides to keep it laying flat. Place your flat ruler on the swatch and measure the inside st st. area. 
Knit a gauge swatch. Measure the gauge swatch with a ruler. If you cast on a different number of stitches than the number recommended for your pattern gauge, you will need to count your stitches. Know that if the number of stitches or rows per inch does not match what the pattern specifies, you will probably need to experiment with different needle sizes. Check the pattern for the sts. Cast on 4 times the sts. Start knitting for five rows of garter stitch. Begin the actual measured swatch knitting keeping the 5 sts. On the first right side row, knit the 5 edge stitches and then *k2tog, yo*. If the rows per inch is noted knit in pattern for 4 times the count. Return to garter stitch and knit another 5 rows. You now have a completed swatch with garter stitch on all sides to keep it laying flat. 