First off, realize that those numbers are 100% arbitrary... a 6 out of 12 on one application may or may not match a 50/100 on another application, even though they are mathematically the same. So don't try to compare those values across applications.
With that in place... what that control is adjusting are the "quantization tables" of the compression algorithm. Usually the are the Luminance and Chrominance quantization tables. These tables describe how much of each type of information is discarded by the compression engine, for different types of repeating patterns. Forexample a "fine" QT might have a very low number in all parts of the table, saying no matter how often a pattern repeats, don't discard it, where as the opposite table would have larger numbers in the areas of the table that are represent frequently occurring patterns. Basically saying "this is a common pattern, you can compress it down a lot more, it's not as important to the image."
Different things that do compression have different sets of tables stored in them. My camera for example has 2 (Fine and Coarse) per jpeg size. (at least I'm betting that Small Fine doesn't use the same tables as Large Fine... but they might!) I've seen a couple cameras that had 4 levels (Low, Normal, Fine, SuperFine). Photoshop traditionally has 13 (0-12), Lightroom claims 101 (1-101) (more on that in a moment.) and I've seen other tools with anywhere from 5 (1-5) to 256! (0-255).
So let's start with Photoshop's 13 levels. Basically they have 13 sets of QTs built into the application which make up spectrum of more and more detail. 0 is horrid, compressing things to well past anything useful. 12 is equally unusable, but for the opposite reason, it can actually result in files LARGER than what would be needed to represent the image in a loss-less compression such as PNG, or even in an uncompressed format like BMP! So why is it there? Well, the commonly accepted reasoning, and I've seen this over and over, was that the original PS team expected most people to use 0-10, and 11 and 12 were left in place for "research" or for bridging over to another application to let it do the compression. (though if you're going to do that, why even export as jpg? just export TIFF or something.)
Now, lightroom's 101 step claim got torn apart pretty well a while back by Jeffrey Friedl. There are two big findings there.
LR maps that 101 values into just 13 different QTs, each 7 or 8 points wide. 93, 95, 99, and 100 for example, all use the same values.
LR 0 doesn't actually resemble anything else's 0 value. It's MUCH better.