Skip to main content

Can You Reverse a Hash?

One of the most common questions about hash functions is:

Can you reverse a hash?

The short answer is:

Not in the same way that encrypted data can be decrypted.

But the frequently heard statement:

"Hashes can't be reversed."

is too imprecise as an absolute claim.

After all, an attacker often doesn't need to mathematically invert a hash at all.

They can try possible inputs.

A Hash Function Has No Decryption Function​

With encryption, there is an intended reverse direction:

Plaintext
↓
Encryption + key
↓
Ciphertext
↓
Decryption + key
↓
Plaintext

With a hash function, it looks different:

Input
↓
Hash function
↓
Hash value

There is no corresponding secret key and no intended decryption algorithm:

Hash value
↓
Decryption?
↓
original input

That's why hashing is not encryption.

I explain what fundamentally distinguishes these techniques in the article What Is a Hash Function?.

Why Can't the Original Value Be Uniquely Contained in the Hash?​

SHA-256 always produces 256 bits of output.

It makes no difference whether the input contains a few characters or a very large file.

That means there are only:

2²⁵⁶

possible SHA-256 hash values.

The possible input space, by contrast, is larger.

Therefore, different inputs must exist that produce the same hash value.

From a hash value, it therefore generally cannot be uniquely determined which of possibly several matching inputs was originally used.

This is closely related to the topic of hash collisions.

What Does Preimage Resistance Mean?​

The cryptographically more precise question is therefore not:

Can I reverse the hash?

But rather:

Can I find a matching input for a given hash value?

This security property is called preimage resistance.

Given is:

H

The goal is to find:

x

such that:

Hash(x) = H

For SHA-256, NIST lists a preimage-resistance strength of 256 bits.

For a generic search, that means an order of magnitude of:

2²⁵⁶

operations.

I explain what lies behind this in detail in the article What Is Preimage Resistance?. I show how to put such security strengths into perspective in the article How Secure Are 128, 256, and 512 Bits?.

But Then Why Are Passwords Found From Hashes?​

Because an attacker doesn't have to calculate the hash backward.

Suppose an attacker has a hash and suspects that the input was a human-chosen password.

They can then try candidates:

"password"
↓
Hash
↓
no match

"123456"
↓
Hash
↓
no match

"summer2026"
↓
Hash
↓
match

If the generated hash matches the target hash, the attacker has found a matching input.

At no point did they reverse the hash function.

They always calculated it in the normal direction.

Brute Force​

In a brute-force attack, possible inputs are tried systematically.

If the possible input space is small enough, this can be very effective.

Take a four-digit PIN:

0000
0001
0002
...
9999

There are only:

10,000

possibilities.

Even if every PIN is hashed with SHA-256, an attacker doesn't have to try 2²⁵⁶ possibilities.

They only have to search the actual input space.

That is a crucial difference.

Dictionary Attacks​

With passwords, it is often even more efficient not to test all theoretically possible character combinations.

Instead, likely candidates can be tried:

password
123456
qwerty
letmein
...

as well as variants of them.

This works because human-chosen passwords aren't evenly randomly distributed across a huge input space.

In such scenarios, the security of a hash value therefore depends not only on the cryptographic hash function.

What About Rainbow Tables?​

Precomputed tables can map hash values to known inputs.

In simplified terms, the principle is:

known input
↓
calculate hash
↓
precompute the result and reuse it later

An attacker then doesn't have to repeat certain calculations for every target.

Individual random salts make such precomputed attacks considerably harder, because the same password input produces different stored results for different salts, and precomputed work can't simply be reused across many accounts.

That is one of the reasons modern password storage uses salts.

In SP 800-63B, NIST requires a suitable password-hashing scheme with a salt and a cost factor for centrally stored passwords.

Why Is SHA-256 Still Not Enough for Passwords?​

SHA-256 was designed as a general-purpose cryptographic hash function and is very fast to compute.

In password attacks, speed is an advantage for the attacker.

Suitable password-hashing schemes therefore use, among other things, a cost factor to deliberately make individual guessing attempts more expensive.

For password verifiers, NIST requires a suitable password-hashing scheme with a salt and a cost factor; the cost factor should be set as high as is practically justifiable.

I cover this topic in detail in the later article "Why Is SHA-256 Not Suitable for Passwords?".

Try It Yourself​

This problem can be demonstrated very well.

The following Hash Guessing Demo generates the SHA-256 hash of a random PIN — or of a PIN you choose yourself.

The tool then tries, in order:

0000
0001
0002
...

hashes each candidate, and compares the result with the target hash until the matching candidate has been found.

Hash Guessing Demo

Start the experiment: a SHA-256 hash value is generated from a PIN – then the PIN is recovered purely by trying candidates.

The SHA-256 hash is not decrypted. The tool tries possible inputs, hashes them and compares the result with the target hash.

PIN length
Secret PIN

Takeaway: A small input space can be searched exhaustively – no matter how strong the hash function is. Preimage resistance only protects if the input is hard to guess.

You can also find this tool in the Tools section.

This makes it immediately visible:

The hash was not decrypted.

Instead, the small input space was searched.

That is probably the most illustrative answer to the question of this article.

So Can You Reverse a Hash?​

If "reverse" means:

Is there a general decryption function that restores the original input from a hash value?

Then the answer is:

No.

But if it means:

Can I find an input that produces a known hash value?

Then the answer is:

Under certain circumstances, yes.

Among other things, the following are decisive:

  • the size and predictability of the input space,
  • the hash algorithm used,
  • known cryptanalytic weaknesses,
  • and, for passwords, the password-hashing construction used.

That's why the statement:

"You can't reverse hashes."

is useful as a first intuition, but not precise enough cryptographically.

The Key Takeaways​

  • Hashing has no intended decryption step.
  • A hash value does not uniquely contain the original input.
  • Cryptographically, what matters is preimage resistance.
  • According to NIST, SHA-256 has 256 bits of preimage resistance.
  • An attacker doesn't have to reverse a hash to find a matching input.
  • Small input spaces can be tried exhaustively.
  • With passwords, likely candidates can be tested deliberately.
  • Salts make it harder to reuse precomputed attacks.
  • Suitable password hashing makes individual guessing attempts more expensive.
  • "Not decryptable" therefore doesn't automatically mean "the input can never be found."

Where To Go From Here​

That completes the "Understanding Security" section.

The four articles connect the theoretical security properties from the fundamentals with their practical significance:

Birthday paradox
↓
Birthday attack
↓
Security strength
↓
Reverse a hash?

From here, individual hash algorithms, password hashing, and concrete attacks can be covered in much greater depth.

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 Preimage-resistance and collision-resistance strengths of the approved hash functions.

  2. National Institute of Standards and Technology (NIST), CSRC Glossary – Security Strength Definition of cryptographic security strength.

  3. National Institute of Standards and Technology (NIST), SP 800-63B – Authentication and Lifecycle Management Requirements for password hashing, salt, and cost factor.