โ† Back to Blog

Hash Collisions Explained: Why They're Dangerous

2026-04-11 ยท 5 min read

โ† Back to Blog

Hash Collisions Explained: Why They're Dangerous

ยท 6 min read

Definition of a Hash Collision

A hash collision occurs when two different inputs, when processed by a hash function, produce exactly the same output (hash value). Since hash functions map infinitely many possible inputs to a finite output space, collisions must mathematically exist (pigeonhole principle). The design goal of secure hash functions is to make collisions extremely difficult to find and exploit in practice.

/* A collision means: */
hash(input_A) == hash(input_B)

/* But: */
input_A != input_B

/* Example (conceptual - not actual MD5): */
MD5(data_A) = "d41d8cd98f00b204e9800998ecf8427e"
MD5(data_B) = "d41d8cd98f00b204e9800998ecf8427e"
/* data_A and data_B are different files! */

Three Types of Collision Attacks

MD5 Collision: Real-World Cases

In 2004, researchers including Xiaoyun Wang published a practical MD5 collision algorithm. In 2008, Marc Stevens and others successfully forged valid SSL/TLS certificates using MD5 collisions. The attack: researchers used MD5's weakness allowing collisions to generate two certificate signing requests with identical MD5 hashes โ€” one legitimate, one containing malicious CA authority. When a CA (using MD5 for verification) signed the legitimate request, that signature was also valid for the malicious version, giving attackers the ability to forge certificates for any website.

SHA1 Collision: The SHAttered Attack

In 2017, Google and CWI Institute announced the SHAttered attack โ€” the first practical collision attack against SHA1. They generated two PDF files with identical SHA1 hash values but different content. The two PDFs had identical opening bytes but different embedded image content โ€” visually distinguishable but with completely identical SHA1 hashes.

This attack used approximately 10^18 SHA1 computations, equivalent to 6,500 CPU-years or 110 GPU-years. In comparison, a general birthday attack would theoretically require 2^80 computations; SHAttered reduced the actual computation to approximately 2^63 through cryptanalytic techniques.

Dangerous Scenarios Enabled by Hash Collisions

How to Defend Against Hash Collision Attacks

Hash Collisions vs. Non-Cryptographic Hash Collisions

In non-cryptographic hash tables, collisions are normal and acceptable โ€” when two keys hash to the same slot, use chaining or open addressing to handle it. Hash table collisions are a performance issue, not a security issue. However, in web frameworks, if attackers can control large numbers of collisions, they may degrade hash table performance to O(n), causing DoS attacks (HashDoS). Modern languages' built-in dictionary/map types typically use random hash seeds to prevent such attacks.

Try the online tool now โ€” no installation, completely free.

Open Tool โ†’

Try the free tool now

Use Free Tool โ†’