How to compress an image to an exact file size (complete guide)
A practical guide to hitting an exact KB target - 20 KB, 100 KB, 1 MB - without trial and error, and without uploading your photos.
Most compressors only give you a vague quality slider, leaving you to guess and re-export until you land near the size you need. If a form demands exactly 100 KB, that's frustrating. Here's how exact-size compression actually works - and how to do it in one shot.
Why a quality slider isn't enough
The relationship between encoder quality and file size isn't linear and depends entirely on the image's content. A flat graphic and a detailed photo at the same quality setting produce wildly different sizes. That's why 'set quality to 80%' rarely hits a specific target.
The binary-search approach
The reliable method is to binary-search the quality value: encode at a mid quality, measure the result, then move the quality up or down depending on whether you're over or under target. Repeating this about a dozen times converges to within a fraction of a KB.
- Start with a quality range of 5-98.
- Encode at the midpoint and check the size.
- If it's under target, push quality higher; if over, lower it.
- Stop once you're within ~5% under the target.
- If even the lowest quality is too big, downscale the dimensions and try again.
Quality first, dimensions second
To preserve sharpness, you should exhaust the quality range before shrinking dimensions. Downscaling is a last resort used only when an image simply can't reach the target at full resolution.
Do it without uploading
All of this can run in your browser with WebAssembly codecs - no server, no upload, no limits. ShrinkTo's compressor does exactly this: pick a target like 100 KB and it hits it on the first try.
Frequently asked questions
What's the smallest size I can compress a photo to?
You can go very small (e.g. 20 KB), but below a point you'll see visible quality loss as the encoder runs out of room and starts downscaling. The tool always keeps quality as high as the target allows.
Does compressing to an exact size upload my photo?
Not with ShrinkTo - the entire process runs locally in your browser.