Compress Image to Exact Size

Shrink a photo to a target file size (20KB, 50KB, 100KB, 200KB or a custom limit) automatically. Free, private, runs entirely in your browser.

🌐 Español

Drop your files here (.jpg, .jpeg, .png, .webp)

🔒 Private by design: your files are processed locally in your browser and never uploaded to any server.

Where a 20 KB or 100 KB upload rule comes from

Byte limits on photo uploads are usually a relic. A government visa portal, a university admissions form or an examination board’s application system was specified when storage and bandwidth were expensive, the rule went into a document, and it has been copied forward ever since. Nobody maintaining that form today can tell you why the number is 20 KB rather than 200 KB, but the validator still rejects anything above it, often with an unhelpful message and a lost session.

The frustrating part is that a quality number is the wrong instrument for the job. You set a number, export, check the file size, find it is 118 KB, set a lower number, export again. This tool inverts the loop: you state the ceiling, and it finds the setting.

The search starts by encoding at quality 100 at the original pixel dimensions. If that already fits, it stops immediately and gives you that file, which is what stops a generous target from needlessly damaging a small image.

When quality 100 is too big, the tool binary-searches the range from 1 to 99 for the highest quality that still lands at or under the target. It tries the midpoint, and if that fits it searches upward for something better, and if it does not it searches downward. The loop is capped at ten iterations, which is comfortably more than the seven or so a binary search over a hundred values actually needs, so the cap exists as a guard rather than as a limit you will hit. Every encode is cached by its exact settings, so the winning attempt is already in memory when the search ends and never has to be redone.

This relies on one assumption that holds for every real JPEG encoder: raising the quality never produces a smaller file for the same image. That monotonic behaviour is what makes a binary search valid here instead of a brute-force sweep through all one hundred values.

What happens when quality alone cannot get there

A 12-megapixel photo asked to fit in 20 KB will not make it on quality alone. Quality 1 on an image that large still carries far too many blocks to describe, and the result would be an unusable smear even if it did fit.

So when the quality search exhausts itself without fitting, the tool shrinks the image itself: both dimensions drop to 85% of the previous round, and the whole quality search runs again at that smaller size. It keeps going, 85% at a time, until something fits or it reaches 10% of the original dimensions. Each new size is produced once by a lossless resize and reused across every quality attempt at that size.

That ordering is deliberate. Losing resolution is usually a better trade than keeping resolution and destroying it, especially for the ID photos and scanned forms this tool exists for, where the destination wanted a modest headshot rather than a DSLR frame in the first place.

JPEG output, even when you hand it a PNG

Whatever you put in, a JPG comes out, named after your original with -compressed.jpg on the end. This is not laziness: the search needs a format with a continuous quality dial, and PNG has none at all. A PNG encoder given a quality value ignores it, which makes a byte target structurally unreachable. WebP does have a dial, but JPEG is the format that portals and legacy forms accept without argument.

The consequence to know about is transparency. JPEG has no alpha channel, so a transparent PNG or WebP is flattened onto solid white before encoding. If that is wrong for your image, Optimize PNG shrinks a PNG without touching a pixel, and Resize Image cuts dimensions while keeping the format.

Driving the target-size compressor

  1. Drop your JPG, PNG or WebP files into the box above, or use Choose files.
  2. Choose a Target file size. The presets cover the limits that come up most often, or pick Custom size (set KB below).
  3. If you chose the custom option, type your figure into Custom target size in KB (only used with “Custom size”). Anything from 1 KB to 10240 KB is accepted.
  4. Click Compress Image to Exact Size. The progress bar advances once per finished file, not once per encoding attempt, so it can sit still for a while on a big photo.
  5. Download the result and check what it weighs. The shell reports a before and after figure for the batch as a whole, and prints a size beside each individual download link, so a run of several photos needs the per-file figure rather than the combined one. Both are rounded to the nearest kilobyte below 1 MB, which means something displayed as 100 KB can still be a few hundred bytes over a strict 100 KB cap. Read the exact byte count in your file manager when the limit is unforgiving.

When the target is genuinely out of reach

If the floor is reached without ever fitting, you still get a file: the smallest one the search produced anywhere along the way. Nothing errors and nothing is hidden, but the size shown next to that download will be above your target, so read it before uploading rather than assuming success.

The usual fix is to crop before compressing. A photo with a lot of irrelevant background spends most of its bytes on detail nobody asked for, and trimming to a centred square or 16:9 frame with Crop Image removes a good part of that cost. For ID portraits specifically, the Passport Photo Maker produces the framing these portals expect before you compress at all.

Target size or quality setting

Use this page when the number you have been given is in kilobytes. Use Compress Images when the number you care about is a quality setting and you simply want the file smaller, since that tool preserves the input format, supports downscaling, and hands back your original bytes rather than a larger re-encode whenever no downscale was applied. Both live on the image tools hub.

See it in action

Screenshot of the Compress Image to Exact Size tool with sysfenix-sample.png (466 KB) loaded, Target file size set to 100 KB, typical form/resume upload limit, Custom target size in KB (only used with "Custom size") set to 100
Compress Image to Exact Size mid-process: sysfenix-sample.png (466 KB) loaded, Target file size set to 100 KB, typical form/resume upload limit, Custom target size in KB (only used with "Custom size") set to 100.
Screenshot of the Compress Image to Exact Size result screen showing sysfenix-sample-compressed.jpg ready to download (100 KB, 79% smaller)
The finished result: sysfenix-sample-compressed.jpg ready to download (100 KB, 79% smaller). The download link is a local blob URL — the file never leaves your device.

Frequently asked questions

Is 100 KB measured as 100,000 bytes or 102,400?

102,400. The target you pick is multiplied by 1024, the binary kilobyte, so 20 KB means 20,480 bytes and 200 KB means 204,800. Portals that state their limit in KB almost always mean the same thing, and where one does not, the few hundred bytes of difference sit well inside the margin the search leaves anyway.

Why is my output smaller than the target rather than right at it?

The search moves in whole quality steps, and JPEG file size jumps rather than sliding smoothly between them. The tool keeps the highest quality that still lands at or under your limit, so the result is usually somewhat under rather than exactly on it. Landing under is the point, since a form that rejects 101 KB does not care that you aimed for 100.

My PNG had a transparent background and the output has a white one. Why?

JPEG has no alpha channel at all, so transparency cannot survive the conversion. Rather than letting transparent pixels composite onto black, which is what drawing straight onto an empty canvas would do, every source is flattened onto solid white first. If the transparency matters more than the byte limit, keep the PNG and optimize it losslessly instead.

What if my photo cannot reach the target even at the lowest setting?

You still get a file, but it will be over your limit. The tool shrinks the image in 15% steps and re-runs the quality search at each smaller size, stopping at 10% of the original dimensions, and if nothing along that path fits it hands back the smallest result it managed. Compare the two sizes shown after the run to see whether it made it.

Does a generous target degrade the photo anyway?

No. The very first thing the search tries is quality 100 at the full original dimensions, and if that already fits inside your limit it stops there and returns it. A 200 KB target against a small screenshot therefore comes back at maximum quality rather than being pushed down to fill the budget.

Why does one photo take several seconds when the tool is running locally?

Because reaching a byte target means encoding the same image over and over. Each attempt is a full JPEG encode, and a strict target against a large photo can involve a dozen or more of them plus a lossless resize per size step. Every intermediate is cached, so no combination is ever encoded twice, but the arithmetic still happens on your own CPU.

Related tools