Two Nearly Identical Files Get Completely Unrelated Hashes
Published 11/24/2026 · 3 min read · Developer tools
Daniel Okonkwo — Front-end developer and tech writer at OneKitly
Web performance · File formats
Checked against 2 sources
Hash "hello" with SHA-1 and you get aaf4c61d…; hash "hellp", one letter apart, and you get d4baaad7…. Comparing the two bit by bit, 85 of the 160 bits differ. Repeat the experiment over five hundred pairs that differ by a single trailing space and the average is 80.5 bits — 50.3%, which is what you would get from two random values. This is the avalanche property, and it is deliberate: a hash function is built so that no information about the input survives into the neighbourhood structure of the output.
Add a single space and 80 of the 160 output bits flip. That is the design working, and it is why you cannot compare hashes to judge similarity.
What to use when you do want similarity
Deduplicating photos, spotting a near-copy of a document or grouping variants of a file all need the opposite property, and they use different tools: perceptual hashes for images, which survive resizing and recompression, and fuzzy or context-triggered hashes for byte streams, which produce comparable values for similar inputs. Neither is a cryptographic hash, and neither should be used to verify integrity — they are built to leak exactly the information SHA-1 is built to destroy.
Half the bits is the target, not an accident
A function whose outputs changed by only ten per cent for a one-bit input change would be a broken one: an attacker could hill-climb towards a target value, and anyone could tell how close two inputs were. Fifty per cent is the value you would get by chance, so it is the value that reveals nothing. When cryptographers publish an avalanche measurement, they are checking that the function has no exploitable structure left, not that it is impressively scrambled.
| Input | SHA-1, first 8 digits | Bits differing from the row above |
|---|---|---|
| hello | aaf4c61d | — |
| hellp | d4baaad7 | 85 of 160 |
| empty string | da39a3ee | about half, as always |
| 500-pair average | — | 80.5 (50.3%) |
Frequently asked questions
- Is SHA-1 still safe to use?
- Not against an adversary. A practical collision was demonstrated in 2017 at a cost of about two to the sixty-third operations, roughly a hundred thousand times cheaper than the two-to-the-eightieth a birthday attack would need, and the cost has fallen since. It is still perfectly adequate for detecting accidental corruption — a truncated download, a flipped bit on disk — because random damage does not aim at anything. Use SHA-256 wherever someone might be trying.
- Why do hashes have a fixed length?
- Because the function compresses an input of any size into a fixed number of bits — 160 for SHA-1, 256 for SHA-256 — which is what makes them comparable and storable. It also means collisions must exist: there are more possible inputs than outputs, by an unimaginable margin. Security does not come from collisions being impossible, only from them being impossible to find on purpose, which is precisely what an attack like the 2017 one removes.
Articles you may find interesting
All guides →Related tools
Sources
Spotted a mistake in this article?