Compressing is not the only lever, and often not the best one
Before you reach for quality, check the dimensions. A modern phone photograph is commonly four thousand pixels wide. If it is going to be displayed at eight hundred, you are storing five times more picture than anybody will ever see, and no amount of clever compression fixes that — you are compressing detail that is going to be thrown away by the browser anyway.
Resize first, compress second. Halving the width quarters the pixel count, and that alone usually gets you under the limit at a quality level where the image still looks good. It is almost always a better trade than keeping a huge picture and crushing it.
The exception is when the image will be printed, zoomed, or used as a source for something else later. Then keep the pixels and accept the size.
What lossy compression actually throws away
JPEG, WebP and AVIF all work on the same insight: the eye is far more sensitive to brightness than to colour, and far more sensitive to broad shapes than to fine detail. So they store colour at lower resolution than brightness, break the image into blocks, and describe each block in terms of a few coarse patterns rather than every pixel. Lowering quality keeps fewer patterns.
That is why the damage shows up first in specific places. Smooth gradients — skies, studio backgrounds, skin — turn into visible bands, because a gentle ramp is exactly what a small number of coarse patterns cannot describe. Sharp edges, especially text and line art, grow a faint halo. Flat blocks of colour survive almost anything.
Which means the right format depends on the picture. A screenshot with text in it compresses terribly as JPEG and perfectly as PNG. A photograph is the opposite. If the thing you are compressing is mostly text or flat colour, you are probably in the wrong format rather than at the wrong quality.
A rough guide to targets
For a photograph destined for a web page, 100–300 KB at the display size is a comfortable range and rarely looks compromised. For an avatar or thumbnail, under 50 KB is normally achievable without anyone noticing. For a document photograph — a receipt, an ID, a form — resist the temptation to go small: legibility matters more than bytes, and something under 1 MB is usually acceptable to whoever asked for it.
If you have to hit a number and cannot, the honest answer is usually to reduce dimensions further rather than to keep pushing quality down. A smaller sharp picture reads better than a large mushy one at every size either of them will ever be viewed at.