A PDF page does not store an image's pixels directly inside its own content. Instead, the page contains an instruction that essentially says draw the image that lives in object 47 at this position, and object 47 is stored separately elsewhere in the file as what is called an image XObject. Recompressing an image means swapping out what object 47 contains, and every page that already pointed at object 47 automatically shows the new, smaller version, with no need to find and rewrite the page content itself. That is also why text, fonts and layout are guaranteed to stay untouched, none of that is walked or modified, only image objects that pass the safety checks are ever rewritten.
Most large PDFs are large because of embedded photographs saved at a much higher resolution and quality than the page actually needs. A photo captured at 4000 pixels wide but displayed at 600 pixels on the page carries roughly 40 times more pixel data than the page will ever show. Each compression level here pairs a JPEG quality setting with a maximum image dimension, so oversized photos are both requantized and, where appropriate, resized down closer to what the page can actually display, which is where most of the real savings come from.
If you want direct control over the exact quality number and dimension cap instead of picking a level, Compress PDF Images exposes those settings manually. And if you need to work with the document's structure first, Merge PDF and Split PDF combine or divide files before you compress the result.