Target File Size Compressor: Complete Guide
The complete guide to compressing images to an exact KB or MB size: custom targets, binary search, scaling, and when to use it.
How the binary quality search finds the sharpest image at any exact KB size: the algorithm, the steps, scaling, and its limits.
CompressMyPic Editorial Team · Published Nov 17, 2026 · 10 min read

How does a tool hit an exact file size like 80KB without guessing? The answer is a simple, elegant algorithm called binary search.
Binary search finds the best quality setting for your image in a handful of tests. It never guesses, never settles for a round number, and never leaves quality on the table.
This article explains how the search works, why it beats manual quality sliders, and where its limits lie.
Every image compresses differently. A portrait at 70 percent quality might weigh 90KB, while a landscape at the same setting weighs 150KB.
That unpredictability makes manual quality sliders useless for exact targets. Setting 70 percent and hoping is not a strategy.
You could try quality after quality by hand, but each test takes time. Finding the best setting manually might take twenty attempts.
The tool solves this with a search. It tests quality levels systematically until it finds the highest one that still fits your target.
Understanding the search helps you trust the result. It is not magic; it is method.
Binary search works on a sorted range. Quality runs from low to high, and file size rises as quality rises, so the range is perfectly ordered.
The search starts in the middle. It tests quality 50 and checks whether the result fits under the target.
If the result fits, the best quality must be higher than 50. The search moves to the upper half and tests 75.
If the result does not fit, the best quality must be lower than 50. The search moves to the lower half and tests 25.
Each test halves the remaining range. After about seven tests, the search has narrowed the best quality down to a single point.
Imagine a photo and a target of 100KB. The search begins by testing quality 50.
At quality 50, the file weighs 70KB. That fits, so the best quality is somewhere above 50. The search tests 75.
At quality 75, the file weighs 120KB. That is too big, so the best quality lies between 50 and 75. The search tests 62.
At quality 62, the file weighs 95KB. That fits, so the range narrows to between 62 and 75. The search tests 68.
At quality 68, the file weighs 104KB. Too big again, so the range becomes 62 to 68. A few more tests settle on 65, which lands at 99KB.
The whole process takes seconds. A human doing the same tests by hand would need many minutes and far more patience.
A linear search tests every quality level in order: 100, 99, 98, and so on. It works, but it is slow.
Finding quality 65 by counting down from 100 takes 35 tests. Binary search finds it in about seven.
Each test involves re-encoding the image, which takes real time. Thirty-five encodings feel sluggish; seven feel instant.
Binary search also scales well. Whether the range is 100 or 1000, the number of tests grows slowly.
That efficiency is why the tool feels fast even on large images. The search does the minimum work needed to find the best answer.
The search runs at full resolution first. That is a deliberate choice, because dimensions matter more to most people than a small quality difference.
A photo at full size with slightly lower quality usually looks better than a smaller photo at high quality. The eye notices size before it notices compression.
Only when the search fails at full size does scaling begin. The tool then tests smaller dimensions, running a fresh quality search at each step.
This order protects your image. It keeps the pixels you have and sacrifices only the quality you cannot see.
When a portal demands exact dimensions, the order still holds. The tool works harder on quality alone, and warns you if the target cannot be met.
When quality alone cannot reach the target, the tool steps the dimensions down. It tests scales like 90 percent, 80 percent, and lower.
At each scale, it runs a fresh binary search for the best quality. That means every dimension gets its own best quality setting.
The tool stops at the first scale that fits. A 90 percent image that hits the target is kept, rather than dropping to 80 percent unnecessarily.
The steps are small on purpose. A gradual reduction preserves as much size as possible while still reaching the target.
For most images, scaling is rarely needed. It appears mainly with very tight targets or very large originals.
The search lands very close to the target, usually within a few kilobytes. It aims just below the line to leave a safety margin.
That margin protects against rounding. A file that reads as 100KB on your device might be 100.4KB in exact bytes, and the margin covers the gap.
Some images defeat the search. A highly detailed photo at a tiny target may need scaling so drastic that the result is unusable.
In those cases, the tool reports an honest miss. It would rather tell you the target cannot be met than hand you a ruined image.
Accuracy also depends on the format. JPG and WebP give the search fine control, while PNG offers almost none, which is why PNG targets often miss.
Manual sliders ask you to pick a quality number and hope. Most people pick a round number like 70 or 80, which is rarely the best choice.
The best quality for your image might be 63 or 71. A human would never guess that number, but the search finds it in seconds.
Manual sliders also waste time. Each test means changing the slider, waiting, and checking the size, repeated until you get lucky.
The search removes the guesswork entirely. You state the target, and the tool finds the best quality that fits it.
That is the real benefit of the target compressor. It turns a trial-and-error chore into a single confident click.
In batch mode, the search runs separately for every image. Each file gets its own best quality setting, even though they share a target.
A simple portrait might settle at quality 82, while a detailed landscape settles at 61. Both hit the same target with their own best settings.
The summary tracks each file individually. It shows which files hit the target and which ones missed, so you can fix the misses one by one.
Batch searching takes longer than a single search, but far less time than compressing each file by hand. The tool does the repetitive work for you.
Preview the hardest files in the batch first. They are the most likely to have missed the target or lost visible quality.
The search cannot create data that does not exist. A tiny, blurry original cannot become a sharp image at any target.
It cannot beat physics either. A detailed photo at 2KB is impossible, and no search algorithm changes that.
It cannot fix a wrong format. A PNG photo at a tight target will miss no matter how clever the search is, because PNG cannot shed enough weight.
In those cases, change the inputs. Use a better original, switch to JPG, or raise the target to something achievable.
The search is a powerful tool, but it works within the limits of your image. Good inputs in, good results out.
Binary search is one of the oldest algorithms in computing. It appears in phone books, dictionaries, and guessing games, anywhere a sorted list must be searched.
The idea is simple: check the middle, discard half, and repeat. It is the same logic as finding a word in a dictionary by opening it in the middle.
Programmers use it to search sorted data of any size. A list of a million entries takes only twenty tests, which is why it is everywhere.
In image compression, the sorted list is the quality range. File size rises with quality, so the range is ordered and binary search applies perfectly.
Knowing the history helps you trust the method. It is not a new trick; it is a proven idea applied to a new problem.
Human instinct is poor at picking quality numbers. We favour round numbers like 70 or 80, which are rarely the best choice for a given image.
Instinct also stops too early. A person who finds a quality that fits usually stops, even if a slightly higher quality would also fit.
The search has no such biases. It tests systematically and stops only when the range is narrowed to a single best value.
That methodical approach is the whole advantage. The tool does not know more than you; it simply checks more carefully than you would.
Trust the method over your gut. The numbers it finds are better than the numbers you would guess, every time.
Quality is usually measured from 1 to 100, giving a hundred possible settings. The search tests about seven of them to find the best.
Seven tests are enough because each test halves the range. After seven halvings, a range of 100 has shrunk to less than one.
Finer steps would add tests without visible benefit. The difference between quality 65 and 66 is invisible to the eye.
The search stops when further tests cannot improve the result. That stopping point is built into the algorithm, not chosen by hand.
Efficiency matters here. Fewer tests mean faster results, and faster results mean a tool people actually enjoy using.
Binary search needs a sorted range: higher quality must mean a larger file. That is almost always true, but not quite always.
Tiny quality changes can occasionally produce a slightly smaller file at a higher quality, due to how encoders round their maths.
These wobbles are small and the search tolerates them. It aims just below the target, so a small wobble cannot push the result over the line.
Format changes break the ordering completely. A PNG at quality 90 may be larger than a JPG at quality 50, which is why the search runs per format.
The tool handles these edges quietly. You see a clean result; the algorithm handles the mess behind the scenes.
Quality search and dimension scaling are two loops, one inside the other. The outer loop tries dimensions; the inner loop searches quality at each size.
The tool starts at full size and searches quality. If no quality fits, it steps the dimensions down and searches again.
That nesting is efficient. It avoids testing every combination of size and quality, which would take far longer.
The result is the largest image at the best quality that fits your target. No other combination beats it within the search space.
Understanding the nesting explains the tool's behaviour. A file that scales down did so because no quality at full size could fit.
The search could get smarter. Future versions might predict the best quality from the image content before testing anything.
Content-aware search would start closer to the answer, needing fewer tests. A portrait and a landscape would start at different quality guesses.
For now, the plain binary search is fast enough. Seven tests take seconds, and the result is already the best quality that fits.
The principle will not change. State the target, search systematically, and deliver the sharpest file that fits.
That principle is what makes the target compressor feel effortless. The complexity lives in the algorithm, and the user sees only a clean result.
For the full guide to custom targets, read Target File Size Compressor: Complete Guide. For the hands-on steps, see How to Compress an Image to an Exact KB Size. To try it yourself, open the target file size compressor and type any size you need.
The complete guide to compressing images to an exact KB or MB size: custom targets, binary search, scaling, and when to use it.
Step-by-step: compress any image to an exact KB size for unusual portal caps. Type the number, run the search, and verify the result.
Compare animated GIF, WebP, and MP4: file size, quality, compatibility, and when to use each format for animations on the web.
Step-by-step: compress any animated GIF for Discord, Slack, websites, and chat. Presets, palette, scale, and fixes for stubborn files.