Short answer
To compress an image to an exact size, the method depends on what the picture is. A PNG, cutout or screenshot goes through getPNG's compress-png tool with a size limit set: 100 KB, 240 KB, 500 KB, 1 MB, 2 MB, or any number you type. It searches for the largest colour palette whose file fits under that number, gives back the best-looking result rather than the first one that squeaks in, and never resizes the picture to get there. A photograph with no transparency has no palette to search, so it goes through a JPG quality setting instead, tried a few steps lower until the file is small enough.
An upload form rarely asks for a picture that is “smaller.” It asks for one under 500 KB, or 240 KB, or 2 MB, a specific number that either your file meets or the form refuses it. That is a different question from the one most compression advice answers, and it needs a different kind of tool: not a quality slider you nudge and re-check by eye, but a search that stops exactly where the number says to stop.
The number itself comes from somewhere else entirely: a government portal’s upload rules, a job application form, an email provider’s attachment limit, a marketplace listing tool. None of those care how the picture got small, only whether it fits, which is why the useful question is never “how do I compress this,” it is “how do I get under this exact number without giving up more than I have to.”
How to compress an image covers the decision that comes first: whether the picture needs to keep a transparent background. This guide picks up from there, once you already know the answer, and covers the part that is specific to hitting a number rather than just getting smaller.
Two different searches, because there are two different files
A PNG, a cutout or a screenshot with transparency has a palette behind it: up to 256 colours, each stored once, with every pixel pointing at one of them. Cutting that palette down is what makes the file smaller, and a computer can try several palette sizes in a fraction of a second and tell you which is the largest one that still fits under a number. That is a search a tool can run for you.
A photograph with no transparency has no palette to search. As a JPG it compresses on a quality setting, a single number that trades detail for size continuously rather than in the jumps a palette moves in. Nothing stops a tool from testing a few quality settings and reporting back, but the two jobs are different underneath, and getPNG only runs the automatic search for the palette case today. For a photograph, the quality slider is yours to move.
Getting a PNG, cutout or screenshot under a number
Open /compress-png and drop the file. Underneath the colour options there is a size limit: buttons for 100 KB, 240 KB, 500 KB, 1 MB and 2 MB, and a plain number field next to them for anything else, from 8 KB up to about 20 MB. Setting a limit takes the colour choice out of your hands on purpose: the row underneath says “the limit decides the palette”, because the whole point is that you stop guessing a colour count and start stating the number the form actually cares about.
The buttons are not arbitrary round numbers. 100 KB, 500 KB, 1 MB and 2 MB cover the sizes an upload form or an email attachment limit asks for most often, and 240 KB has its own reason: it is the exact figure the US visa and Diversity Visa lottery uploads use for the digital photo, common enough that typing it each time would be wasted effort. If the number you were given does not match any of the five, the field next to them takes it directly, in kilobytes, and the search behind it works exactly the same way.
Behind that button, the tool tries a run of candidate palette sizes, from 256 colours down to 8, and keeps narrowing in on the largest one whose resulting file is still under your limit. It is not looking for the first palette that happens to fit; it is looking for the best-looking one that does, which is why a picture given a generous limit often comes back close to 256 colours rather than settling for less than it needed to. Once it has an answer, two more rules apply whatever the limit was: the file is never handed back larger than the one you gave it, and the picture itself, its pixels, is never resized to help it fit. Only the palette moves.
When the search finds nothing under the limit, even at eight colours, it does not fail silently. It hands back the smallest file it managed, tells you the limit was not met, and stops there rather than reaching for a lever, resizing, that changes what is actually in the picture. That is a deliberate line: a compressor that quietly resizes your photograph to hit a number has answered a different question than the one you asked, even if the resulting file happens to be small enough.
The Smooth gradients setting stays live underneath a size limit too, and it is worth leaving on for a photographic cutout. It spreads the rounding error each pixel picks up from the smaller palette into its neighbours, which turns visible banding across a soft shadow or a sky into a much finer texture instead. Turn it off for flat artwork, a logo or a screenshot, where there is no gradient to protect and the extra texture only works against the file getting smaller.
Getting a photograph under a number
A photograph with no transparent background belongs in JPG, and JPG’s lever is a quality setting rather than a palette. Convert it to JPG and start around 85: that is usually visibly indistinguishable from the original and already considerably smaller than the same picture as a PNG. Check the resulting file size, and if it is still over the number the form wants, convert again a step or two lower, 70 or 60, and check again. There is no button on the general converter that takes a target number of kilobytes and finds the right quality by itself the way the PNG size limit does; the quality is yours to move, and the check is yours to make each time.
That gap is not universal on getPNG. The passport photo tool runs exactly that kind of search internally for a JPEG: several of the twelve documents it supports set a byte limit on the digital photo, and the tool steps a candidate quality down, 0.92, then lower, until the file fits, occasionally stepping back up if a very plain photo compresses below a floor the rules also set. It is built for those documents specifically rather than offered as something you can point at any JPG and any number, which is why the manual approach above is still the general answer for a photograph today.
The manual version is still only a handful of tries in practice. A JPG’s size moves roughly in step with its quality number rather than jumping unpredictably the way a palette search does across eight candidates, so two or three conversions, 85, then 70, then 60 if it is still not enough, usually finds a number close enough to the limit without much detail lost. The picture to watch while you do it is the same one a palette search protects automatically: zoom in on a hard edge or a patch of text partway through, because that is where a JPG’s blocks show first, well before the rest of the photo looks any different.
When it will not fit no matter what
Both searches run out eventually. A very large photograph asked to fit under a very small number will not get there on colours or quality alone, because past a point the file’s size is set by how many pixels it has rather than how each one is stored. When that happens, the pixel count is the lever that is actually large enough to matter: reducing a PNG’s file size covers resizing to the size the picture is actually shown at, which on its own often removes three quarters of the file before a palette or a quality setting does anything at all. Resize first, then run the size limit search again on the smaller file; it will usually find a much better palette to work with, because there is simply less picture left to store.
Resizing is the one step here you cannot undo later, which is the reason neither search does it for you. Keep the original at its full size somewhere, and treat the resized, compressed copy as the one you upload rather than the one you keep.
Watch the same picture ask for a different palette at three limits
- Drop a photographic cutout with a soft edge, hair or fur is a good test, on /compress-png.
- Set the size limit to 500 KB and note the colour count and file size in the row.
- Lower the limit to 100 KB on the same file, then to whatever your own number field allows below that.
You should see: the colour count drops each time the limit tightens, and the edge stays a soft fade rather than turning into a hard outline, because the search only ever gives up colours, never pixels.
If you do not: if the row says the limit was not met even at the lowest setting, the picture has more pixels than that limit can hold at any colour count. Resize it smaller and try the same limit again.
The free way
Need the cutout before the size limit?
getPNG removes a background at the full resolution of the original photo, with nothing uploaded. Once you have the cutout, /compress-png is where the size limit search above actually runs.
The steps, in short
- Work out what the picture is. A photograph with no transparent background and a PNG, cutout or screenshot are two different jobs. Only the second has a palette to search, which is what a size limit needs.
- For a PNG, cutout or screenshot: set a size limit. Open getPNG's compress-png tool, drop the file, and pick a size limit: one of the buttons, or your own number in kilobytes.
- Read what came back. The row shows the colour count it settled on, the before and after size, and whether the limit was actually met. Nothing is resized to get there.
- For a photograph: lower the JPG quality and check. Convert with a quality setting, look at the resulting size, and step the quality down if it is still too big. There is no automatic search for a JPG the way there is for a palette.
- If even the smallest palette will not fit. The picture has more pixels than the limit can hold at any colour count. Resize it to the size it is actually shown at first, then run the size limit again.
Questions
How do I compress an image to exactly 200 KB?
If it needs to keep a transparent background, or it is a screenshot or flat artwork, use getPNG's compress-png tool: type 200 in the size limit field and it searches for the largest colour palette that still fits under 200 KB, without resizing the picture. If it is a photograph with no transparency, convert it to JPG and lower the quality setting a step at a time until the file comes in under 200 KB; there is no automatic search for that case, only for a palette.
Why did the compressor not just resize my picture to hit the size I asked for?
Because a smaller number of pixels is a different picture, and a tool that quietly shrinks the one you gave it has answered a different question from the one you asked. getPNG's size limit search only changes the colour palette. If a form's limit genuinely cannot be met without fewer pixels, resizing is a decision worth making on purpose, not one worth hiding inside a compressor.
What happens if even the smallest palette is still too big?
The tool tries down to eight colours, which is close to the smallest a picture can usefully hold, and if that PNG is still over the limit it hands back the smallest one it managed, marks the limit as not met, and says so. It never returns something larger than what you gave it, and it never resizes behind your back to force a fit.
Why is 240 KB one of the size limit buttons?
Because the US visa and Diversity Visa lottery uploads use that exact number for the digital photo, and it is common enough to earn its own button rather than being typed in each time. The other buttons, 100 KB, 500 KB, 1 MB and 2 MB, cover the sizes upload forms and email attachments ask for most often.
Does compressing to a size limit lose the transparent background?
No. The size limit search in getPNG's compress-png tool only changes how many colours the palette holds; a cutout's soft edge, including a hair edge that fades to nothing, is still stored as a fade rather than becoming a hard line. Converting to JPG to hit a size is the one path that does remove transparency, because JPG has nowhere to store it.
Can I compress a JPG to an exact size the same automatic way?
Not on getPNG's general compressor, which only ever writes a PNG. A photograph belongs in JPG for size reasons, but getting it under a specific number today means lowering the quality setting yourself and checking the result, rather than typing a number and letting a search find it. getPNG's own passport photo tool does run that kind of search internally, stepping a JPEG's quality down until a document's own byte limit is met, but that is built for the twelve documents it covers rather than offered as a general tool.