Skip to main content

How Secure Are 128, 256, and 512 Bits?

In cryptography, we constantly encounter numbers like:

128 bits
256 bits
512 bits

The bigger, the more secure?

In principle, a bigger number can mean a bigger possible search space.

But with hash functions, there's a crucial catch:

Hash length and security strength are not the same thing.

A SHA-256 hash is 256 bits long.

Nevertheless, SHA-256 does not offer 256 bits of security against every class of attack.

What Does "128 Bits of Security" Mean?​

NIST defines security strength in terms of the amount of work needed to break a cryptographic algorithm or system.

In simplified terms:

128 bits of security
≈
2¹²⁸ operations

and correspondingly:

256 bits of security
≈
2²⁵⁶ operations

So the number doesn't simply describe the length of a string.

It describes an order of magnitude of the expected attack effort.

How Big Is 2¹²⁸?​

2¹²⁸ corresponds to roughly:

3.4 × 10³⁸

possible states, or a corresponding order of magnitude of basic operations in a generic search.

For comparison:

2²⁵⁶ ≈ 1.16 × 10⁷⁷

The crucial point:

Adding one bit doubles the search space.

2¹²⁸

is therefore not "half as large" as:

2²⁵⁶

The difference is exponential.

What Does This Mean for SHA-256?​

SHA-256 produces:

256 bits

of output.

However, the different security properties yield different values.

NIST lists the following for SHA-256:

PropertySecurity strength
Collision resistance128 bits
Preimage resistance256 bits
Second-preimage resistancedepends on the message length

Why?

In a preimage attack, a given hash value has to be hit.

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

2²⁵⁶

In a collision, by contrast, only any pair of identical hash values has to be found.

Because of the birthday bound, the generic effort is:

2¹²⁸

I explain the meaning of these properties in the articles What Is Preimage Resistance? and What Is Collision Resistance?.

I explain why NIST specifies the second-preimage-resistance strength of SHA-256 as 256 − L(M) bits, and therefore as dependent on the message length, in the article What Is Second-Preimage Resistance?.

I explain how SHA-256 is built internally in the article What Is SHA-256?.

And SHA-512?​

SHA-512 produces an output of:

512 bits

NIST lists the following for it:

PropertySecurity strength
Collision resistance256 bits
Preimage resistance512 bits
Second-preimage resistancedepends on the message length

So here, too:

512-bit hash length
≠
512 bits of collision security

The generic collision resistance is 256 bits.

Is 512 Bits Therefore Twice as Secure as 256 Bits?​

That wording would be misleading.

Cryptographic security strengths grow exponentially.

Between:

2¹²⁸

and:

2²⁵⁶

there is no factor of 2.

The quotient is:

2²⁵⁶ / 2¹²⁸
=
2¹²⁸

Raising the security strength from 128 to 256 bits therefore increases the generic search effort by a factor of 2¹²⁸ itself.

That's why cryptographic bit figures shouldn't be compared like ordinary linear quantities.

128-Bit Hash Length Is Not 128 Bits of Collision Security​

This point is especially important.

An ideal hash with 128 bits of output has, generically, only roughly:

64 bits

of collision resistance.

An ideal hash with 256 bits of output:

128 bits

and with 512 bits of output:

256 bits

This gives:

Hash outputGeneric preimage securityGeneric collision security
128 bits128 bits64 bits
256 bits256 bits128 bits
512 bits512 bits256 bits

This table describes the generic expectation for ideal hash functions. The actual security of a specific algorithm may be lower due to cryptanalytic weaknesses.

I explain where the halving for collisions comes from in the articles The Birthday Paradox and How Does a Birthday Attack Work?.

Why Isn't the Bit Count Alone Enough?​

Stating a bit length doesn't yet answer whether a specific system is secure.

To answer that, it must be clear, among other things:

  • which algorithm is used,
  • which security property is being considered,
  • whether known cryptanalytic attacks exist,
  • how the scheme is used,
  • and how large, or how predictable, the actual input space is.

A weak password, for example, doesn't become strong just because it is hashed with SHA-512.

If the attacker knows the input comes from a small candidate space, they can deliberately try those candidates.

Try the Orders of Magnitude Yourself​

With the following Security Bits Calculator, you can select security strengths from 64 to 512 bits and see what order of magnitude lies behind 2^n.

The direct comparison of two values is particularly revealing: it shows why 256 bits doesn't simply mean "twice as much" as 128 bits.

In the lower part, you can also see how hash length, preimage security, and collision security differ from one another.

Security Bits Calculator

Choose a security strength and see what amount of work lies behind the bit count – and why hash length and security strength are not the same thing.

Security strength

128 bits of security

2128

≈ 3.40 × 1038

This is the order of magnitude of attempts a generic attack needs. Every additional bit doubles the effort.

Show exact value of 2128 (39 digits)
340,282,366,920,938,463,463,374,607,431,768,211,456

Compare two security strengths

2256 / 2128 = 2128

≈ 3.40 × 1038

256 bits of security does not mean twice as much effort as 128 bits of security, but 2128 times as much.

Hash length ≠ security strength

Ideal hash function with output length
Or NIST values for

Generic expectation for an ideal 256-bit hash function

Hash output
256 bits
Generic preimage security
256 bits ≈ 2256
Generic collision security
128 bits ≈ 2128

This is the generic expectation for an ideal hash function: preimage attacks need roughly 2n attempts, collisions only roughly 2n/2 because of the birthday bound. A real hash function does not automatically reach these values – MD5, for example, has a 128-bit output but is practically broken in terms of collision resistance.

Takeaway: Security strength grows exponentially: every bit doubles the effort. And the collision security of an n-bit hash is generically only n/2 bits.

You can also find this tool in the Tools section.

And What About Quantum Computers?​

Quantum computers change how certain cryptographic problems are assessed.

In particular, Grover's algorithm can, in theory, speed up an unstructured search quadratically.

However, that doesn't mean that all bit figures may simply be halved across the board, or that today's hash functions automatically become insecure as a result.

The practical assessment depends on the attack, the algorithm, and the quantum resources required.

NIST therefore uses its own security categories for post-quantum security and compares schemes, among other things, with the attack costs against AES and hash functions.

The topic deserves an article of its own and shouldn't be reduced to the statement "quantum computers halve security."

The Key Takeaways​

  • Security strength describes the expected effort to break a cryptographic security property.
  • N bits of security correspond roughly to an order of magnitude of 2^N basic operations.
  • Hash length and security strength are not the same thing.
  • SHA-256 has 256 bits of preimage resistance, but 128 bits of collision resistance.
  • SHA-512 has 512 bits of preimage resistance, but 256 bits of collision resistance.
  • For ideal hash functions, the generic collision security is roughly half the output length.
  • Cryptographic bit figures grow exponentially, not linearly.
  • A large hash length doesn't protect a small or predictable input space.
  • Quantum attacks should be assessed separately, not through a blanket "halve the bits" rule.

Where To Go From Here​

With that, we know what cryptographic bit figures actually say.

One question keeps coming up with hash functions, though:

If a hash is a one-way function — can it really never be reversed?

That's exactly what the next article is about:

Can You Reverse a Hash?

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), CSRC Glossary – Security Strength Definition of security strength.

  2. National Institute of Standards and Technology (NIST), Hash Functions Security strengths of the approved hash functions, including SHA-256 and SHA-512.

  3. National Institute of Standards and Technology (NIST), SP 800-57 Part 1 Rev. 5 – Recommendation for Key Management: Part 1 – General Classification of cryptographic security strengths.

  4. National Institute of Standards and Technology (NIST), Post-Quantum Cryptography – Security (Evaluation Criteria) Security categories for post-quantum schemes, taking quantum attacks into account.