How to Compress an Image to an Exact File Size (KB)
September 8, 2026 · 6 min read
A form demands a photo under 50KB. Yours is 4MB. You drag a quality slider to 60, check the result, it is 180KB. You try 40, get 90KB. You try 25 and now the face has gone blotchy and it is still 60KB.
This is the wrong way round, and almost every compressor makes you do it. You have a target in bytes and the tool is asking you for a number in quality percent, which are related but not in any way you can predict by eye.
Why quality settings do not map to file size
The quality setting in a JPEG encoder does not mean "make the file this big". It controls how aggressively the encoder discards detail, and how many bytes that saves depends entirely on what is in the picture.
Compression works by finding redundancy. A photo of a plain wall has enormous redundancy and compresses to almost nothing. A photo of gravel, foliage or a crowd has very little, because every pixel differs from its neighbour, so there is far less for the encoder to throw away.
That means quality 60 might produce 40KB for a portrait against a plain backdrop and 300KB for a landscape full of trees. Same setting, same dimensions, seven times the size. No fixed quality value corresponds to a fixed file size, which is why guessing never converges quickly.
What byte targeting actually does
The reliable approach is to search for the setting rather than guess it.
Encode the image at quality 50. Measure the result. Too big? Everything above 50 is now ruled out, so try 25. Too small? Try 37. Each attempt halves the remaining range, and after about eight attempts you have found the highest quality that still fits under your limit, usually within a few hundred bytes of the target.
This is a binary search, and a computer does all eight passes faster than you can drag a slider once. Our compressor has a size mode where you type the limit and it runs this search for you. You never touch a quality setting.
The practical difference is that you get the best image that fits, rather than the first one that happened to squeak under while you were guessing downwards.
Dimensions do most of the work
Before you compress at all, check the pixel dimensions, because this is where people lose the most quality unnecessarily.
File size is driven primarily by pixel count. A 4000-pixel-wide photo has around 12 million pixels. Forcing that into 50KB means roughly 4 bytes for every 100 pixels, and the encoder can only reach that by destroying the image.
Resize the same photo to 800 pixels wide first and you have 96 percent fewer pixels to store. Now 50KB is comfortable, and the quality setting needed to reach it is high enough that you will not see the compression at all.
The order that works:
- Convert the format if needed. Most forms want JPG. If yours is a HEIC from an iPhone, convert it first.
- Resize to the dimensions the form actually needs, using the resizer. If the instructions specify a pixel size, use exactly that.
- Compress to the target, and let the search find the quality.
Doing it in that order is the difference between a 50KB photo that looks fine and one that looks like it was faxed.
Why PNG cannot hit a size target
If your image is a PNG and the compressor refuses to target a size, this is why.
PNG compression is lossless. It has no quality dial to turn down — it stores every pixel exactly, and the only variables are how the data is arranged and how many distinct colours the palette holds. There is no continuous setting to search across, so byte targeting does not apply.
To hit a size target you need a lossy format, which means JPEG or WebP. Converting a photographic PNG to JPEG often cuts the size by 80 percent on its own, before any compression setting is involved.
The exception is a screenshot or a flat graphic. Those compress badly as JPEG — sharp edges and text are exactly what JPEG handles worst — so you may be better reducing the dimensions and keeping PNG, if the form allows it.
When it genuinely will not fit
Some limits are brutally tight. Certain government and recruitment portals ask for images under 20KB, which is small enough that technique matters more than tooling.
Reduce the dimensions to exactly what is asked for, and no more. Portals demanding 20KB almost always specify pixel dimensions too. Resize to those exact numbers. Any extra pixels are pure cost.
Start from a good original. Compression can only work with what it is given. A sharp, well-lit photo at 20KB looks far better than a soft, noisy one at the same size, because noise is random detail and random detail is exactly what does not compress.
A plain background helps enormously. A person against a blank wall compresses dramatically better than the same person in front of a bookshelf. This is why passport photo requirements specify plain backgrounds — partly for recognition, and partly because it makes the file small.
Check for a minimum. Plenty of portals specify a range, such as 10KB to 20KB, and will reject a file that is under the floor just as firmly. If aggressive compression is still failing, you may have gone too small.
Read the official notice, not a blog. Requirements differ between portals and change between years, and a wrong number here means a rejected application. Whatever any site tells you, including this one, the authoritative source is the instruction document for the specific form you are filling.
About the files you are compressing
The images people compress to exact sizes are usually the sensitive ones — ID photos, signatures, certificates, scanned documents.
Most online compressors upload your file to a server, process it there and send it back. Several state that files are deleted after a couple of hours, which means they are stored in the meantime.
Our tools run entirely in your browser. Nothing is uploaded. You can confirm this yourself: open developer tools, switch to the Network tab, and compress an image. There will be no upload request. That check works on any site making the same claim, and it is worth thirty seconds before you hand over a scan of your passport.
The short version
Quality settings and file sizes are not linked in any predictable way, so guessing a quality value is the slow path. Resize first, because pixel count dominates file size. Then let a byte-targeting tool search for the highest quality that fits your limit. And if the target is very small, spend your effort on the source photo and the dimensions rather than on the compressor — that is where the quality actually comes from.