A socket wrench is just what you might think it is: a wrench with a socket on the end into which the nut you’re trying to turn fits.
Of course, you’d need a separate wrench for each different size nut.
That’s a lot of wrenches.
So instead, the socket wrench is broken into two pieces: the bit that fits on the nut, called the socket, and the bit you hold in your hand, which has some cams and pinions inside so it will turn in only one direction (and a little lever on the back so you can set it for screwing on or screwing off), called the ratchet. They snap together using a big square boss on the ratchet and a matching hole on the socket.
Naturally, it would be unwieldy to use the same ratchet that can handle a socket for a 35mm nut to turn a socket for a 5mm nut. so there are a few different size big square parts. They have names like “quarter-inch”, “three-eighths inch”, and so on. And I’m sure those names have something to do with the size of the boss—the smaller named ones are smaller—but they’re not as simple as just measuring it. You just have to learn to recognize the different sizes. Luckily there are few and they’re different enough that there’s little chance of mistaking one for the other. Generally the smaller sized sockets go on the smaller sized ratchets, but there is a large overlap where you can get a given size socket to fit either of two different sized ratchets.
Of course you still always seem to end up with a 1/4″ socket you need to snap onto a 3/8″ ratchet. So there are adapters. Usually only down (small socket on big ratchet), and usually only one step.
Sometimes you need to reach the socket way down deep or past an obstruction to get the socket on the nut and have the ratchet somewhere where you can actually turn it. So there are extension rods in various lengths. And “wobble connectors” and bendy joints.
The sockets themselves can be had in 6-point (to exactly fit a normal nut) or 12-point (More common. Easier to get onto the nut at the cost of a little bit of the leverage, and as a bonus they’ll fit the oddball square nuts), and regular and deep socket (the deep ones are invaluable for getting onto a nut that is threaded far down a long bolt…) There are also some special sockets for special uses; spark-plug sockets for instance are a little deeper than normal and have a rubber grommet inside to grip the end of the spark plug and keep it in the socket when it’s not threaded into its hole. And you can get parts that fit onto your ratchets that will drive other things, like some of the bigger hex keys or star-drive keys. I’ve even seen a thing that fits onto the ratchet and turns a car’s oil filter, which is like 5 inches across.
Basically socket wrenches are a way to build the tool need to turn that nut.
I’ve never broken a socket. Or any part of a socket set except a ratchet. So I don’t much worry about the quality of the sockets, and pay careful attention to the quality of the ratchets I buy. There are a few brands that are guaranteed for life; Craftsman used to be but I hear they no longer are. Snap-On still are. So pay attention to the guarantee, and also to the quality: “guaranteed for life” is fine, but still annoying if you have to go get it replaced every few weeks.
Like with drill bits, what will happen is that you’ll buy a set of sockets to start out with (they come in metric and “SAE” (which is what sockets measured in inches are marked. Has to do with auto mechanics somehow. It’s not important to me to know why); you’ll inevitably need both), and use three or four of them all the time while the rest languish. But no way of knowing which few your adventures will call for, so buy the set. And again like drill bits you can buy them individually if you find you need a deep 12-point 7/16″ socket.
Sometimes, you need a lot of leverage. For that you need a “breaker bar“, which looks a lot like a ratchet, but has no ratchet mechanism. It’s just a long lever with a boss on the end to put a socket onto. And if that’s still not long enough you can slip a piece of pipe onto it and have a really long lever if that’s what you need. If you do that, something is going to break. Hopefully the nut will break free from being stuck. More likely your bolt with snap off with the nut still attached. (Or the head of the bolt will snap off, if that’s what you’re trying to turn.) You’ve got it open, but now you have a lot more work to do getting the rest of the bolt out before you can put your thing back together.
That’s why they call it a breaker bar. (Don’t try that trick with the pipe on a ratchet. You’ll just break the ratchety-parts.)