How to Compress an Image to an Exact File Size (KB or MB)

Most image compressors give you a quality slider and let you guess. You move it to 70%, download the result, check the file size, find it's still too large, go back, move the slider lower, repeat. It's tedious — and it still doesn't guarantee you land on the exact number a portal is asking for.

The ResizeImageOnline compressor lets you type in a target file size in KB or MB and hit it directly — no guessing, no iterations. This article explains why most tools can't do this, how binary-search compression works, and the limits of what any tool can achieve when targets are very small.

Why quality sliders don't hit exact file sizes

JPEG and WebP compression don't work by targeting a file size. They work by targeting a quality level — a setting that controls how aggressively high-frequency detail is discarded. The relationship between quality and file size varies by image content:

  • A complex photograph at quality 80 might produce a 350KB file.
  • A simple graphic with flat colours at the same quality 80 might produce a 35KB file.
  • The same photograph at quality 60 might be 200KB; at quality 40, 120KB.

The curve is not linear, and it shifts with every image. A quality slider gives you control over how much quality you trade away — not control over the final file size. That's why guessing with a slider rarely lands you exactly at "under 50KB" or "between 20KB and 50KB."

How binary-search compression works

A tool that targets an exact file size has to run multiple compression passes. The approach is similar to binary search:

  1. Start at quality 85. Check the output file size.
  2. If it's too large, try quality 60. If it's too small, try quality 92.
  3. Continue narrowing the range until the output is within the target range.

This takes several passes — typically 4–8 — which is why it can't be done manually in a reasonable time. Our compressor runs this process in your browser using the Canvas API, so your image never leaves your device.

Common file size targets and the tools for them:

The hard limit: dimensions vs file size

Here's the part most guides skip. File size is a function of both quality and pixel count. A 4000×3000px photograph at quality 85 might be 2.5MB. Reduce quality to 40% and you might get it to 400KB — but with severe visible artifacts. The only way to get that same image to 50KB is to reduce its pixel dimensions as well.

A rough rule: for a target of 20KB, most photos need to be under 800×600px. For 50KB, under 1200×900px at moderate quality. If a portal requires both a minimum pixel dimension (e.g., "at least 600×800px") and a maximum file size (e.g., "under 50KB"), you're working within a constrained range — and you may need to reduce quality more aggressively than usual.

When a portal's combination of minimum dimensions and maximum file size is very tight, it means they are intentionally accepting lower-quality images. Their system is designed for that. Don't try to keep the quality high — meet the constraints and move on.

KB vs MB: the exact thresholds

One source of confusion is that file sizes are reported differently by different systems. The precise values are:

  • 1 KB = 1,024 bytes
  • 1 MB = 1,048,576 bytes (= 1,024 KB)

Some portals specify limits in "KB" and mean exactly this. A portal that says "maximum 50KB" means the file must be 51,200 bytes or fewer. If your compressor reports sizes in decimal (where 1KB = 1,000 bytes), your 50KB output might actually be 50,000 bytes — safely within range — or it might be reported as 49KB in decimal terms. When a portal's check is strict, aim for 5–10% below the stated maximum to account for rounding and byte-counting differences.

What to do when nothing works

If you've compressed the image and it's still above the portal's limit, the next step is to reduce the pixel dimensions. Use our image compressor to set a pixel width or use a separate resizer, then compress again. The combination of reduced dimensions and moderate quality almost always reaches any target size without visually unacceptable quality loss.

Why do most image compressors not hit an exact file size?

JPEG compression targets a quality level, not a file size. The relationship between quality and output size varies by image content — the same quality setting produces very different file sizes for a complex photo versus a flat graphic. Hitting an exact size requires multiple compression passes with a binary-search approach.

What is the smallest a JPG can be without looking degraded?

For a photograph, quality 60–70% is visually acceptable for most uses. Below quality 40%, JPEG blocking artifacts become severe. For very small targets under 20KB, reducing the image dimensions is usually necessary alongside quality reduction.

Why does my image keep failing the portal's file size check?

Common reasons: the portal also checks pixel dimensions (not just file size); you're mixing up KB and MB; or the portal counts bytes differently from your file manager. Aim 5–10% below the stated maximum to give yourself a margin.

Can PNG files be compressed to an exact size?

Not directly — PNG is lossless with no quality dial. To hit a size target with a PNG source, the tool converts it to JPEG or WebP first. If you need PNG output specifically, reducing image dimensions is the most effective lever.

Does resizing the image help?

Significantly. File size scales with pixel count — halving both dimensions reduces pixel count by 75%. A 3000×2000px image at quality 85 will always be larger than a 1500×1000px image at the same quality. For targets under 50KB, reducing dimensions is often necessary.