Hash Collisions: When Different Files Leave the Same Mark
A hash collision happens when two different inputs produce exactly the same hash value. The files can be different even though the short values used to represent them match.
A hash function is a procedure that calculates a compact value from data. With a fixed-length hash, that output—also called a digest—has the same length whether the input is a short message or a large file.
Give the same function exactly the same input again and you'll get the same output. A collision requires different inputs.
Why collisions have to exist
Consider a deliberately tiny example: a hash that produces only three decimal digits, from 000 to 999. It has just 1,000 possible outputs.
If you hash 1,001 different files, at least two must receive the same output. There aren't enough values to give every file its own.
Real security hashes offer vastly more possible outputs, but their fixed size still limits the choices. When possible inputs outnumber possible outputs, some inputs must share a digest.
Why Do Hashing Algorithms Keep Changing?
The security goal is therefore to make collisions impractical to find. Collision resistance means an attacker shouldn't be able to find a matching pair with a feasible amount of computing effort, as the National Institute of Standards and Technology (NIST) definition explains.
That distinction separates a mathematical fact from a useful attack. Knowing that a pair exists doesn't tell you how to find it.
A real collision broke a familiar assumption
In 2017, researchers from Google and the Dutch research institute CWI demonstrated two PDF documents with different visible contents but the same SHA-1 digest. SHA-1 is the name of an older cryptographic hash function, designed for security uses.
The researchers' announcement explained how they constructed the pair and why relying on SHA-1 for collision resistance was unsafe. Their work was a practical demonstration, not just a prediction that collisions should exist.
A system that treats a matching weak hash as sufficient proof that two documents are identical can therefore make the wrong decision. That matters when the hash is used to recognize an approved file or detect a replacement.
Finding any pair isn't the same as matching your file
Several attacks involving hashes sound similar but set different tasks for the attacker:
| Task | What the attacker gets to choose |
|---|---|
| Collision attack | Find any two different inputs with the same digest |
| Second-preimage attack | Given a particular input, find a different input with its digest |
| Preimage attack | Given a digest, find an input that produces it |
NIST separately defines resistance to second-preimage attacks and preimage attacks. A successful collision demonstration doesn't automatically solve those other problems.
For example, constructing two new files together is different from taking a specific file someone already approved and making a replacement with its digest. The attacker's control over the inputs matters.
- Pull the drive from an old computer and read it on your laptop in a minute or two.
- Build a home practice lab for imaging and file recovery with free tools like Autopsy.
- Swap drives without tools or a reboot, so your time goes to the data and not the hardware.
Choose the hash for the job
For security applications that need collision resistance, use a currently suitable cryptographic hash. NIST recommends moving away from SHA-1 and identifies SHA-2 and SHA-3 as alternatives; SHA-256 belongs to the SHA-2 family.
A longer-looking digest alone isn't evidence of strength. The function's design and known weaknesses matter, too.
Password storage has an additional requirement: make repeated guesses expensive. Security nonprofit OWASP recommends dedicated password-hashing methods, such as Argon2id, with a unique salt, a random value included when hashing each stored password.
Fast file hashes such as plain SHA-256 aren't suitable substitutes for those methods. And finding any pair of colliding passwords wouldn't automatically grant access to a particular account: the saved result for that account, its salt, and its checking process determine what input will be accepted.
A matching hash can be powerful evidence in a well-designed system. Its value comes from the chosen method and the way it's used, not from a promise that collisions are impossible.
Hash Functions: Small Outputs With a Big Job

MD5: Two Different Files Can Have the Same Fingerprint

SHA-1 Still Computes a Hash. The Security Promise Failed.

QUOTE:
"Amateurs hack systems, professionals hack people."
