Skip to content
OmniTools

Compress Image to Exact KB

Hit an exact file-size target such as 20KB, 50KB or 100KB without guessing or losing legibility.

All image tools

Compress image to an exact file size

This tool runs entirely in your browser. Nothing you enter is uploaded, stored, or logged.

What this tool does

Upload forms demand a file within a size range and reject anything larger, which is why "compress to 20KB" is one of the most repeated requests in image tooling. A slider-based compressor cannot do this, because it changes quality without any relationship to the resulting byte count. This tool targets a specific number of kilobytes instead, and finds the exact quality setting that lands inside your limit.

How it works

A JPEG's file size is not linear in its quality setting. Dropping quality from 90 to 80 may barely change the size, while 20 to 15 can halve it. Because the relationship is curved, the tool binary-searches the quality parameter: it encodes at the midpoint, measures the result, and narrows the range until it finds the highest quality that still fits.

The size limit is almost always a maximum, so the target is set slightly below it. This is deliberate headroom. Many portals re-encode an upload on the server, and a file sitting exactly at the limit can be pushed over by that re-save and rejected.

If the image cannot reach the target at even the lowest quality, the tool reduces the pixel dimensions as well, because no amount of quality reduction can push a very large image below a very small limit. When that happens the result says so, rather than quietly returning something that misses the target.

Worked example

Compressing a 4MB passport photo to fit a 50KB limit, where a plain quality slider has no way to land on the target.

  1. Encode at quality 0.5 → 310KB, over the 47KB working limit
  2. Encode at quality 0.25 → 96KB, still over
  3. Encode at quality 0.125 → 48KB, over
  4. Binary search converges on quality ≈ 0.115 → 46.8KB

The highest quality that fits under 47KB is used, giving 46.8KB with a small safety margin below the 50KB portal limit.

Accuracy and limitations

  • Reducing quality is lossy. Text and faces lose the most detail, so check the result before submitting anything important.
  • If the source is a PNG with transparency, converting to JPEG flattens the transparency onto a background. The tool warns before doing this.
  • The portal's own re-compression may change the file after upload. Leave headroom rather than targeting the limit exactly.

Frequently asked questions

How do I compress a photo to exactly 20KB?
Set the target to 20KB and this tool will find the highest quality that fits beneath it. If the image is too large to reach 20KB on quality alone, the dimensions are reduced as well and the tool tells you it did so.
Why not just use a quality slider?
Because JPEG size is not linear in quality. A slider gives you a relative change, not a target. Binary search on the quality parameter is what makes a specific byte count reachable, and it guarantees you get the highest quality that still fits.
Why target slightly below the limit instead of exactly at it?
Portals frequently re-encode uploads, and metadata or a re-save can push a file that was exactly at the limit over it. A small margin, roughly 5%, avoids most rejections caused by landing exactly on the boundary.
Does my photo get uploaded anywhere?
No. The image is decoded, resized, re-encoded, and measured entirely in your browser using the canvas API. The file never touches a server, which is also why there is no waiting for an upload on a slow connection.
Will compressing to 20KB make my photo unusable?
It depends on the pixel dimensions. A small ID photo at 20KB can stay perfectly legible, while a large landscape at the same size will be heavily degraded or forced down in dimensions. The tool reports the final dimensions and size so you can judge.