Skip to main content

What Is Collision Resistance?

One of the most important security properties of cryptographic hash functions is what's known as collision resistance.

It's about the following task:

Can I find two different inputs that produce the same hash value?

Simplified:

find:

x and y

such that:

x ≠ y

and

Hash(x) = Hash(y)

For a collision-resistant hash function, it should be practically impossible to deliberately find such a pair.

This property is called collision resistance.

Collision Resistance Doesn't Mean No Collisions Exist​

That's the most important point, first.

Collision resistance does not mean a hash function has no collisions.

For a hash function with a fixed output length, collisions are mathematically unavoidable.

SHA-256, for example, produces a hash value with 256 bits.

That means there are:

2²⁵⁶

possible SHA-256 hash values.

The possible input space, on the other hand, is larger.

That's why different inputs must exist that map to the same hash value.

Collision resistance, therefore, doesn't ask:

Do collisions exist?

But rather:

Can we find a collision with practical effort?

Why collisions are mathematically unavoidable is explained in detail in the article What Is a Hash Collision?.

What Does a Collision Attack Look Like?​

In a collision attack, no specific hash value is given.

The attacker searches for two different inputs:

x ≠ y

such that:

Hash(x) = Hash(y)

Simplified:

x ──→ hash function ──┐
├──→ same hash value
y ──→ hash function ──┘

Which specific hash value ultimately results doesn't matter for the actual collision search.

What matters is only that two different inputs have the same hash value.

Why Does SHA-256 Only Have 128 Bits of Collision Resistance?​

SHA-256 produces a hash value with 256 bits.

You might therefore initially expect:

256-bit hash
=
256 bits of collision security

That's not the case, though.

For an ideal hash function with an output length of n bits, the generic collision resistance, due to the birthday bound, is approximately:

n / 2 bits

or an effort on the order of magnitude of:

2^(n/2)

For SHA-256, that works out to:

2^(256/2)
=
2^128

NIST therefore classifies SHA-256 with a collision-resistance strength of 128 bits.

This isn't some specific flaw or weakness of SHA-256.

It's the expected generic collision security of an ideal 256-bit hash.

Why Does the Birthday Paradox Help an Attacker?​

The reason for the halved security strength is that the attacker doesn't have to hit one specific hash value.

They're only looking for any pair of different inputs with the same hash.

That resembles the well-known birthday problem.

With 23 people, the probability is already around 50.7 percent that at least two of them share the same calendar birthday — under the usual simplifying assumptions.

Here, we're not looking for someone with a particular birthday.

We're simply asking:

Is there any pair with the same birthday?

The situation is similar with hash values.

As the number of calculated hash values grows, the number of possible pairs increases very quickly.

That's why a collision becomes statistically relevant much earlier than hitting one specific, predetermined hash value.

I explain this relationship in more detail in the article The Birthday Paradox, and how an attacker deliberately exploits it in the article How Does a Birthday Attack Work?.

Collision Resistance and Preimage Resistance Are Not the Same​

The difference becomes especially clear when you compare the tasks directly.

Preimage Resistance​

A specific hash value H is given:

given:

H

find:

x

such that:

Hash(x) = H

For an ideal 256-bit hash function, the generic effort is on the order of:

2²⁵⁶

Collision Resistance​

No specific hash value is given:

find:

x and y

such that:

x ≠ y

and

Hash(x) = Hash(y)

Due to the birthday bound, the generic effort for an ideal 256-bit hash is, on the other hand, on the order of:

2¹²⁸

That's why NIST lists SHA-256 with:

PropertySecurity strength
Preimage resistance256 bits
Collision resistance128 bits

What preimage resistance means exactly is explained in the article What Is Preimage Resistance?.

Collision Resistance and Second-Preimage Resistance Are Also Different​

Second-preimage resistance also shouldn't be confused with collision resistance.

In a second-preimage attack, a specific input x is already given:

given:

x

find:

y

such that:

x ≠ y

and

Hash(x) = Hash(y)

In a collision attack, on the other hand, the attacker may search for both inputs:

find:

x and y

such that:

x ≠ y

and

Hash(x) = Hash(y)

This extra freedom is decisive.

A practical method for finding collisions therefore doesn't automatically mean a second preimage can be found for any arbitrary existing message.

The differences are explained in more detail in the article What Is Second-Preimage Resistance?.

Why Can Collisions Be Dangerous?​

Collisions can become problematic when an application assumes that different relevant data can't practically end up with the same hash value.

An especially important area of application is digital signatures.

Simplified, often not the entire message is signed directly — instead, a cryptographic hash value of the message is included in the signing process.

If an attacker can deliberately construct two different messages so that they have the same hash value, that can, depending on the procedure used and the specific circumstances, endanger the security of such an application.

That's why collision resistance is an important security property for cryptographic hash functions used in digital signature schemes.

What matters again here:

In a collision attack, the attacker can influence both colliding messages.

That's what distinguishes it from a second-preimage attack.

What Happens When Collision Resistance Is Broken?​

A practical collision attack means the expected generic effort is no longer necessary, because a better method is known.

That's exactly what happened with older hash functions.

MD5​

Practical collision attacks are known for MD5.

MD5 should therefore not be used, according to RFC 6151, for applications that need collision resistance.

SHA-1​

The collision resistance of SHA-1 is also considered broken.

In 2017, SHAttered demonstrated, for the first time, a practical collision for the full SHA-1 hash function.

Two different PDF files were constructed so that they have the same SHA-1 hash.

That vividly shows the difference between:

collisions exist mathematically

and:

collisions can be practically, deliberately found

Only the second statement is the decisive cryptographic security break.

Does a Collision Attack Mean You Can Reverse Hashes?​

No.

That's an important distinction.

If collision resistance is broken, that doesn't automatically mean preimage resistance is also broken.

An attacker might be able to construct two inputs:

x ≠ y

with:

Hash(x) = Hash(y)

That doesn't mean, though, that they can find a matching input for an arbitrary, given hash value H.

That would be a preimage attack.

The various security properties of a hash function can therefore be broken to different degrees.

Does Good Avalanche Behavior Mean Collision Resistance?​

Also no.

The avalanche effect is about a small change to the input affecting many bits of the output.

Collision resistance, on the other hand, answers the question of how difficult it is to find two different inputs with the same hash value.

A hash function can show convincing avalanche behavior and still have cryptographic weaknesses.

The avalanche effect alone, therefore, doesn't prove collision resistance.

How the effect works, and how the changed bits can be measured, is shown in the article What Is the Avalanche Effect?.

The Three Resistance Properties Compared​

This lets us line up the three fundamental problems directly, side by side.

PropertyGivenSearched for
Preimage resistancehash value Hx with Hash(x) = H
Second-preimage resistanceinput xdifferent y with the same hash
Collision resistancenothing specificarbitrary different x and y with the same hash

For SHA-256, NIST lists, among others, these security strengths:

PropertySHA-256
Preimage resistance256 bits
Collision resistance128 bits
Second-preimage resistancedepends on the message length

This makes it clear why the three properties must be considered separately.

What such bit figures mean in concrete terms is explained in the article How Secure Are 128, 256, and 512 Bits?.

The Key Takeaways​

Collision resistance describes the difficulty of finding two different inputs with the same hash value.

We're looking for:

x and y

with:

x ≠ y

and

Hash(x) = Hash(y)

The most important points:

  • Collision resistance doesn't mean no collisions exist.
  • Collisions are mathematically unavoidable for hash functions with a limited output length.
  • What matters is how difficult it is to deliberately find a collision.
  • For a collision, no specific hash value is given.
  • For an ideal n-bit hash, the generic collision effort is on the order of 2^(n/2).
  • SHA-256 therefore has 128 bits of collision resistance.
  • SHA-256 simultaneously has 256 bits of preimage resistance.
  • Collision resistance is not the same as preimage resistance.
  • Collision resistance is not the same as second-preimage resistance.
  • A collision attack doesn't automatically mean hash values can be reversed.
  • Good avalanche behavior also doesn't prove collision resistance.

That separates the three central resistance properties of cryptographic hash functions from one another.

Where To Go From Here​

With:

  • hash functions
  • hash collisions
  • the avalanche effect
  • preimage resistance
  • second-preimage resistance
  • collision resistance

the most important fundamentals are now in place.

That completes the fundamentals section.

In the Understanding Security section, I'll next show what these properties mean in practice — starting with:

The Birthday Paradox

After that, you can go deeper into individual topics — for example, how SHA-256 works, broken hash functions, or password hashing.

Sources and Standards​

The following primary and standards sources form the basis for the technical statements in this article:

  1. National Institute of Standards and Technology (NIST), Hash Functions Definitions and security strengths of collision, preimage, and second-preimage resistance.

  2. National Institute of Standards and Technology (NIST), FIPS 180-4 – Secure Hash Standard (SHS) Official specification of SHA-1 and SHA-2, including SHA-256.

  3. National Institute of Standards and Technology (NIST), SP 800-107 Rev. 1 – Recommendation for Applications Using Approved Hash Algorithms Background on security properties of cryptographic hash functions and their use. NIST announced in late 2022 that it would withdraw this publication; the supplementary content was moved to the NIST Hash Functions page.

  4. IETF, RFC 6151 – Updated Security Considerations for the MD5 Message-Digest and the HMAC-MD5 Algorithms IETF security considerations on MD5 and collision resistance.

  5. Marc Stevens, Elie Bursztein, Pierre Karpman, Ange Albertini, Yarik Markov, The First Collision for Full SHA-1, CRYPTO 2017. Primary source for the practical SHA-1 collision.