For the uninitiated, gauge is a term used by knitters to describe the type of fabric they are creating – the size of the stitches, mainly. Frankly, if you don't knit, this post will bore and confuse you.
So, when I started knitting – and really, up until very recently – I thought of gauge as a pattern-specific thing. I'd open up a new issue of Vogue Knitting, or download something from Ravelry and see that the designer wanted me to get 17 stitches per inch and think "OK, that's what THAT DESIGN is knit at, and if I want it to fit properly I have to get that same gauge." (This is, of course, true.) This left me with three options if I wanted to knit that pattern:
1. Use the exact same yarn the pattern calls for
2. Somehow magically stumble onto a yarn that knit up at the same gauge
3. Adjust the pattern to work with a different gauge
Number 2 really did feel like only magic would help, because I didn't really understand yarn weights, which I'll get to in a second.
Every knitter has a personal gauge, inherent to the way they knit. You may be a tight knitter, who has to work hard to get your tips into the stitch, or you might be a loose knitter who has to worry about stitches falling off your needles. Your gauge may change when you work in the round versus flat, and it might change depending on the fiber you are knitting with - more loosely when working with superwash, acrylic or other slippery yarns, for example. You might be like me, pretty much in the middle on stitch gauge (number of stitches per inch) but very loose when it comes to row gauge (number of rows per inch.)
If you are a new knitter, your gauge may change over the course of your knitting. That scarf you started might be very tight at one end, and loose at the other. It will probably stabilize as you get more adept and knitting becomes as second-nature as holding a pencil.
When you see the gauge listed on a knitting pattern, one element of what you are reading is that designer's personal gauge. To replicate the pattern, you'll have to find a way to match it. If you know your own tendencies, you can go in armed with that information. Maybe you already know you'll need to go down a needle size, or use sharp-tipped metal needles. When you shop for needles, the clerk at the shop may ask you about your personal gauge. The general wisdom is that tight knitters should use slick needles (metal or coated plastic) and loose knitters should use sticky ones (bamboo or other woods.)
Yarns are classified into different weights. At the fine end are lace and fingering, DK and worsted are in the middle, with Aran, Chunky and Bulky at the thicker end. (This is a simplification, but man, there are a lot of classes of yarn.) It wasn't until I started consulting at Espace Tricot that I saw that what these classifications are, really, are gauges. These categories tell you what gauge this yarn is suited for. Most yarns carry this information on the label. It shows you a little square - 10cm x 10cm - and tells you how many stitches you can expect this yarn to make in that space, when matched with the appropriate needle.
Obviously, you can knit any yarn with any needle you like (although really thick yarn with really small needles may prove physically impossible). You can knit your fingering weight yarn (which lists 32 sts on 2 mm needles) on 5mm needles and get an open, airy fabric. Some patterns may ask you to do exactly this. But most of the time, the gauge listed in a pattern and the gauge listed on a yarn ball band are going to square up. Any minor inconsistencies are probably down to personal gauge - the designer's and yours - and can be accounted for by adjusting needle size.
Writing this down, it seems so obvious, but I honestly didn't really get it until I started helping other knitters find substitute yarns while working at Espace Tricot. My experience before then had been so personal, so much just doing my own thing, that I didn't see the bigger picture. Gauge is not the only factor in finding a substitute yarn – fiber content and texture are important too – but it sure does help. If you can go into your LYS and say "I need a DK weight yarn that knits up to 22 stitches per inch on 3.5mm needles in stockinette, with a smooth texture, and I tend to knit loosely" you will not only delight the clerk working there, you are much more likely to find suitable yarns.
Sometimes I see a knitting pattern in my Ravelry feed or in a book and think "Ah, I love that! But instead of buying new yarn to make it, I'm going to use something from my stash." But a visit to the stash later, I realize I don't have enough Worsted on hand, but I do have plenty of this lovely hand-dyed DK. And then madness of recalculating the pattern begins. For some patterns, it's easy to change yarn weights - a delicate shawl can be a thick wrap. A simple raglan sweater might take some number crunching, but hey, I've designed patterns from scratch, I can handle it!
But why was the pattern designed using that yarn? If it's in a big magazine, possibly because the brand advertises there. But it's also a conscious and important choice a designer makes, and it affects proportion, fit and feel. When you change it, you risk losing some element of the design that made it so appealing to you in the first place. You may not think that having a cable twist 12 times on its way up a sweater is much different from 15 times, but you might be surprised. You might think that adding a single repeat of a colourwork motif to the yoke of sweater is harmless, but it might take away some indefinable element of symmetry.
Granted, it might be fine, but you won't know until you've put an awful lot of work into it.
I'm not saying you shouldn't adjust patterns - I do it often, though less often than I used to. Part of that is laziness. If I want to do a whole bunch of math, I'll cook up something of my own. But part of that is caution born of experience. I sympathize with knitters who don't wear standard sizes and often have to make these kinds of adjustments just to make something that fits.
In conclusion, I guess what I'm trying to say is that gauge really is one of the most important things in knitting, so when a pattern exhorts you to knit a gauge swatch, there's a reason. And when you think about altering a design, think about how gauge contributes to the pattern and whether changing it will leave the parts you like so much about it intact.