Type the cap the form gave you. Eight encodes at most, in a worker, and the largest file that fits underneath it — or a straight answer that the format cannot get there.
How the search finds the number
There is no formula that turns a byte target into a quality setting. The relationship depends on the picture: a photograph of a wall and a photograph of a forest at the same dimensions and the same quality differ by a factor of five. The only reliable way to hit a cap is to encode, measure and encode again.
- 1The first trial is the floor — JPEG quality 5, or a two-colour palette. If the floor is still over your cap, no setting on that axis will fit, and you are told so after a single encode.
- 2If the floor fits, it becomes the answer to fall back on and the search bisects upward, each trial taking the half of the range that is still worth looking at.
- 3For a PNG there is one extra trial before all of that: the lossless pass. If the file fits under the cap without a pixel changing, the search stops there, because nothing improves on that.
- 4The search stops after eight encodes or when the range closes, whichever comes first, and returns the largest file it found under the cap.
All of it runs in a worker. Eight full re-encodes of a twelve megapixel photograph on the main thread is a frozen tab; here the page keeps drawing and the trial list fills in as each one lands.
When the cap cannot be met
A cap is unreachable when the picture has more pixels than the cap has room for. Twenty kilobytes across four thousand by three thousand pixels works out at one byte for roughly every six hundred of them, and no JPEG encoder writes a photograph that thin without turning it into blocks.
At that point this page stops and tells you the smallest file it could make. The next step — reducing the long edge — changes the picture's dimensions rather than its bytes, so it happens only when you say so: press the button that names the dimensions, or switch on “Allow smaller dimensions” before the run. This tool never quietly makes a picture smaller to make a number look right.
The format step is offered, never taken for you.
When the floor still overshoots, the panel lists what can still give, cheapest change first: the MozJPEG encoder if the browser's writer was running, 4:2:0 chroma if you had chosen 4:4:4, a more efficient format (WebP or AVIF), and only then fewer pixels. Each is one click and none is applied on its own. On a form route, or with an upload spec chosen, the format rung is left out: a portal that asks for a JPG will refuse a WebP.
Kilobytes, and which kilobyte
- A kilobyte is counted as 1,024 bytes by default, and the exact byte figure is printed beside the control. A switch under the cap counts 1,000 instead, for forms that say so.
- Upload forms are inconsistent about this, so the stricter reading is the default: a file under the cap at 1,024 bytes to the kilobyte is also under it at 1,000.
- The search aims 2% under the cap unless you move the margin, because a file a few bytes under a limit is one rounding away from being over it.
- The size a form checks is the size on disk. It does not care what the picture looks like or what it once weighed, which is why the result here is the file itself rather than an estimate of one.
Questions people arrive with
Why is the result 18.6 KB when I asked for 20 KB?
Is a kilobyte 1000 bytes or 1024 here?
What happens when the cap cannot be reached?
How many times does it encode my file?
The form wants 20 KB and also a fixed pixel size. Which do I do first?
Elsewhere on this site
- Upload limits on Indian exam portalsThe bands each field tends to fall in, why a form rejects a file that looks correct, and the order to work in when both dimensions and bytes are capped.
- Why this JPEG will not get smallerWhat to do when the floor is still over the cap and the picture is already small.
- Photo resizer in KBWhen the form also fixes the pixels: width × height and the KB cap, solved together.
- Photo size in KB for formsPick the exam or service; its sourced pixels, range and format are set together and checked.
