What Is SHA-256?
SHA-256 is a hash function: it takes any input and produces a fixed 64-character hexadecimal output. The same input always gives the same output, and changing one character changes the result completely.
What a hash function does
It maps data of any size to a fixed-size value, deterministically and irreversibly. There is no key and no way back from the hash to the input except by guessing inputs and hashing them.
SHA-256 is part of the SHA-2 family, published by NIST and specified in FIPS 180-4. It is one of the most widely deployed hash functions in the world.
Hash any text in the browser.
Open the SHA-256 Hash Generator →The properties that matter
| Property | Meaning | Why it matters |
|---|---|---|
| Deterministic | Same input, same output | Comparison is trivial |
| Fast | Cheap to compute | Usable on large files |
| Avalanche effect | Small change, totally different hash | Detects any modification |
| Collision resistant | Hard to find two inputs with one hash | Prevents substitution |
The last property is the one that makes a hash useful for integrity. If two different files could produce the same hash, a hash would prove nothing.
A worked example
Hashing the text hello gives 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. Changing it to Hello gives a completely different string.
That is the avalanche effect. There is no visible relationship between the two outputs, and no way to predict the change.
Where SHA-256 is used
- File checksums, so a download can be verified.
What it does not do
It does not encrypt anything. It does not hide the input, and it does not provide secrecy.
It also does not protect against tampering by itself: if an attacker can change the file, they can change the published hash too. The hash only helps when the expected value comes from a trusted source.
Passwords and why SHA-256 is wrong for them
A password hash needs to be slow, so that guessing is expensive. SHA-256 is designed to be fast, which makes it a poor choice for storing passwords.
Use a dedicated password hashing function such as bcrypt, scrypt or Argon2, which are deliberately slow and salted. A plain SHA-256 of a password is crackable at billions of guesses per second.
Salting and why it matters
A salt is random data added to the input before hashing, so identical inputs produce different hashes. That stops an attacker from precomputing a table of common hashes.
Salts are stored alongside the hash and do not need to be secret. Their job is to make each hash unique.
Comparing hashes safely
Compare the full value, and where the comparison is part of a security check, use a constant-time comparison so that timing does not leak how much matched.
In application code, use the platform function rather than writing the loop.
Common mistakes
- Using SHA-256 to store passwords.
- Assuming a hash hides the content.
- Comparing only the first few characters of a hash.
- Trusting a checksum published on the same server as the file.
- Hashing a string with an unexpected encoding, such as adding a trailing newline.
Encoding traps
The same text hashed as UTF-8 and as UTF-16 gives different results, and a trailing newline changes the hash entirely.
When comparing hashes from different tools, confirm the input bytes are identical. Most mismatches are a newline or an encoding difference, not a broken hash.
Hashing a file versus hashing text
A file hash covers every byte, including the exact line endings and any metadata stored inside the file. Two files that look identical on screen can hash differently if one was saved on Windows and the other on Linux.
When a published checksum does not match, compare the file size first. A different size means a different file; the same size with a different hash suggests an encoding or line-ending difference rather than a corrupted download.
What SHA-256 is not for
A plain SHA-256 hash is fast, which is the wrong property for storing passwords. Fast hashing lets an attacker try billions of guesses per second.
For passwords use a slow, salted algorithm designed for that job, as described in NIST SP 800-63B.
SHA-256 is a good fit for checking file integrity, comparing downloads against a published checksum, and building digital signatures.
Frequently asked questions
Can SHA-256 be reversed?
No. You can only guess inputs and hash them.
Is SHA-256 still secure?
For integrity and signatures, yes. It is not a password storage function.
What is a SHA-256 hash used for?
Verifying that data has not changed, and as the input to a digital signature.