DEV Community

Cover image for ๐Ÿ“ Compress Image to KB: 20 KB ยท 50 KB ยท 100 KB ยท 200 KB โ€” hit the number exactly
Tomaz
Tomaz

Posted on Originally published at tooladda.online

๐Ÿ“ Compress Image to KB: 20 KB ยท 50 KB ยท 100 KB ยท 200 KB โ€” hit the number exactly

โšก 10-second version

The form says "photo must be between 20 KB and 50 KB". Most compressors give you a quality slider and let you guess. tooladda.online/image-compress-to-kb.html takes the number and searches for the best quality that lands inside it.

โ— Important

These are your ID photos, signatures and marksheets. Compressed locally โ€” nothing uploaded, nothing retained after the application window closes.


๐ŸŽฏ Why a slider can't do this, and a search can

Say you need 50 KB. There is no fixed JPEG quality value that produces 50 KB, because the output size depends entirely on the image's content โ€” a photo of a plain wall and a photo of a forest at the same quality differ by a factor of five.

So the only reliable method is to measure and adjust:

try quality 80  โ†’  180 KB   too big
try quality 55  โ†’   74 KB   still too big
try quality 40  โ†’   46 KB   under โ€” but is there headroom?
try quality 45  โ†’   51 KB   just over
try quality 43  โ†’   49 KB   โœ… best fit
Enter fullscreen mode Exit fullscreen mode

That's a binary search, and it converges in a handful of passes. The result is the largest file that still satisfies the limit โ€” so your photo is as legible as the rule permits, instead of a needlessly ugly 22 KB when 49 KB was allowed.

The minimum is the part that catches people

Government and exam portals almost always specify a range, not a ceiling:

Spec What fails
"Photo: 20 KB โ€“ 50 KB" A 12 KB file. Under the minimum fails too.
"Signature: 10 KB โ€“ 20 KB" An 8 KB file, and a 25 KB file
"Photo max 200 KB" Only files above 200 KB

If you blindly maximise compression you'll fail the minimum and never understand why. Range mode exists for exactly this.

And the format trap

Format On a small photo Verdict
JPEG Compresses smoothly; easy to tune to any KB target โœ… Almost always the right answer
PNG Lossless โ€” often cannot get under 50 KB at the required pixel size โš ๏ธ Only if the portal demands PNG

If you're stuck above the ceiling with a PNG and the form accepts JPEG, switching format is the fix.


๐Ÿงญ How it works

Diagram


โœจ What's inside

### ๐ŸŽฏ Presets for real form limits 20, 50, 100, 200 and 500 KB โ€” the numbers that actually appear on Indian exam and government portals โ€” plus any custom value. ### โ†”๏ธ Min **and** max ranges Land between two numbers, which is how the specs are genuinely written. Compressing "as small as possible" fails half of them.
### ๐Ÿ” Best-fit search Converges on the largest acceptable file so your photo stays readable. A face compressed into mush fails human verification even when the validator passes it. ### ๐Ÿ“ Pixel dimensions too Most forms specify pixels *and* KB. Set both in one pass instead of bouncing between two tools.

๐Ÿ› ๏ธ Where the limit bites

Form Typical spec
๐ŸŽ“ SSC CGL / CHSL Photo 20โ€“50 KB, signature 10โ€“20 KB
๐Ÿ›๏ธ UPSC Photo and signature with separate ranges
๐Ÿฆ IBPS / bank exams Photo, signature, thumb impression, declaration โ€” four specs
๐Ÿชช PAN / Aadhaar / KYC Photo within a defined size
๐ŸŽซ Visa portals Frequently a hard per-file cap
๐ŸŽ“ University admissions Portal-specific, usually undocumented until rejection

๐Ÿ“– Four steps

1.  Open   โ†’  tooladda.online/image-compress-to-kb.html
2.  Drop   โ†’  your photo or signature
3.  Set    โ†’  the range (min AND max) + required pixel size
4.  Check  โ†’  still legible? โ†’ download
Enter fullscreen mode Exit fullscreen mode

โ–ถ Compress now โ€” tooladda.online/image-compress-to-kb.html

๐Ÿ’ก Tip

Aim just inside the band โ€” target 45 KB for a "20โ€“50 KB" spec rather than 49.9 KB. Some portals measure in KiB vs KB or reject files sitting exactly on the boundary, and the visual difference between 45 and 50 KB is nothing.


โ“ FAQ

Is it free?

Free, no watermark, no signup, unlimited images.

Are my photos uploaded?

No โ€” compression runs in your browser.

My file is below the minimum and still rejected. Why?

Because the spec is a range and you're under it. Use range mode so the output lands inside the window.

Why can't my PNG get under 50 KB?

PNG is lossless โ€” it can't discard detail. Convert to JPEG if the form allows it.

Will the photo still be acceptable at 20 KB?

Usually yes at passport-photo pixel sizes, which is why the specs are written that way. Always eyeball the output before submitting.

What about the PDF size limit on the same form?

Use Compress PDF โ€” it has the same target-size approach for documents.


๐Ÿ”ฌ Under the hood

  • Iterative encode-and-measure search over JPEG quality (and dimensions when needed), client-side.
  • Honours both a minimum and a maximum, because real specs are ranges.
  • No upload endpoint; works offline once loaded.

Originally published on ToolAdda, where Compress Image to KB runs free in your browser โ€” nothing is uploaded, nothing leaves your device.

Top comments (0)