On this page
What is SHA256?
SHA256 (written SHA-256 in the standards) is a cryptographic hash function. You give it data of any length and it returns a digest that is always exactly 256 bits long. Written in hexadecimal, that is 64 characters.
A good hash function has three properties that make it useful:
- Deterministic: the same input always produces the same digest, on any computer.
- One way: you cannot work backwards from the digest to the input.
- Collision resistant: nobody can find two different inputs that produce the same digest.
Hashing is not encryption. There is no key and nothing to decrypt. If that difference is still fuzzy, our guide to hashing vs encoding vs encryption puts the three side by side.
SHA256 example: one character changes everything
Here are the SHA256 digests of three short strings. The only difference between the first two is a capital H, yet the outputs share no visible pattern. This is called the avalanche effect.
hello 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
abc ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adA 4 GB video produces a digest of exactly the same length as the word "abc". The output size never depends on the input size.
Hash algorithm SHA256 and the SHA-2 family
SHA-2 is a family of six functions: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256. The number is the digest length in bits. SHA256 is the one you will meet most often, because it is fast, compact and supported everywhere.
Who created SHA256?
The US National Security Agency (NSA) designed the SHA-2 family, and the US National Institute of Standards and Technology (NIST) published it as a federal standard in 2001 and 2002. The current specification is NIST FIPS 180-4. The design is public, and cryptographers worldwide have studied it for over two decades.
How does SHA256 work?
SHA256 never looks at your message all at once. It chops it into equal pieces and feeds them one by one into a mixing function, carrying a running 256-bit state from piece to piece. The final state is the digest.
SHA256 algorithm steps
- Convert to bits. Text is first turned into bytes, usually UTF-8, so the algorithm only ever sees a stream of bits.
- Pad the message. Append a single 1 bit, then enough 0 bits that the length is 64 bits short of a multiple of 512. Finally append the original message length as a 64-bit number.
- Split into 512-bit blocks. After padding, the message divides exactly into blocks of 512 bits (64 bytes).
- Set the starting state. Eight 32-bit words, taken from the fractional parts of the square roots of the first eight prime numbers, form the initial hash value.
- Expand each block. Each block's 16 words are stretched into a message schedule of 64 words using shifts, rotations and additions.
- Run 64 compression rounds. Eight working variables (a to h) are mixed in 64 rounds. Each round uses one schedule word and one round constant, taken from the cube roots of the first 64 primes.
- Add and repeat. The mixed result is added to the running state, and the next block starts from there.
- Output the digest. After the last block, the eight 32-bit words are joined into the final 256-bit digest.
Each round computes two temporary values from the working variables. It uses bit rotations, a "choose" function (bits of e pick between bits of f and g) and a "majority" function (each output bit is the majority vote of a, b and c). It then shifts the variables down one place and injects the new values into a and e. All additions are modulo 232, so values wrap around instead of growing. After 64 rounds every output bit depends on every input bit of the block.
Why the length goes into the padding
Adding the message length means two messages that differ only in trailing zero bits still pad differently, so they cannot accidentally end up with the same digest.
This chained, block-by-block design is called the Merkle-Damgard construction. It has one known quirk, length extension, which comes up again in the SHA3 comparison below.
What is SHA256 used for?
Anywhere software needs a short, trustworthy fingerprint of data, SHA256 is the default choice.
- File checksums. Download pages publish a SHA256 value so you can confirm the file you got is the exact file they released. Our walkthrough on how to verify a file checksum shows the commands for Windows, macOS and Linux.
- API request signing. Many APIs sign requests with HMAC-SHA256, which combines the hash with a secret key. The HMAC guide explains why a plain hash cannot do this job.
- TLS certificates and code signing. Certificates and signed software hash their contents with SHA256 and sign the digest instead of the whole file.
- Git and content addressing. Storage systems name data by its hash, so identical content is stored once and any corruption is obvious.
- Key derivation. SHA256 is the building block inside key derivation functions such as PBKDF2.
How SecretNote uses SHA256 in PBKDF2 key derivation
SecretNote encrypts notes in the browser with AES-GCM. The encryption key is not used raw: the code derives it with PBKDF2 using SHA-256 as the hash, a fresh random 16-byte salt per note and 100,000 iterations. SHA256 does the hashing, and PBKDF2 repeats it many times so that every guess costs an attacker real work.
SHA256 in Bitcoin
Bitcoin relies on SHA256 in two places. Miners hash each block header twice with SHA256 (double SHA256) and keep changing a number in the header until the digest falls below a target value. That search is the proof of work. Transaction IDs are also double SHA256 digests. Because SHA256 is one way, the only way to find a winning digest is to keep guessing, which is exactly what makes the work provable.
Is SHA256 secure?
Yes. As of 2026 there is no practical attack on SHA256's collision resistance or preimage resistance. Finding a collision by brute force takes around 2128 attempts, and reversing a digest takes around 2256. Both are far beyond any computer that exists.
Quantum computers do not change the picture much. Grover's algorithm would in theory cut the preimage search to around 2128 steps, which is still out of reach. NIST continues to approve SHA256 for signatures, certificates and key derivation.
What SHA256 cannot protect is a predictable input. If the input is a short password or a 6-digit PIN, an attacker simply hashes every candidate and compares. That is not a flaw in SHA256; it is why passwords need a different tool.
How does SHA256 compare to MD5, SHA512 and SHA3?
| Algorithm | Digest size | Hex length | Status |
|---|---|---|---|
| MD5 | 128 bits | 32 | Broken: collisions are practical |
| SHA-1 | 160 bits | 40 | Broken: public collision since 2017 |
| SHA-256 | 256 bits | 64 | Secure, the common default |
| SHA-512 | 512 bits | 128 | Secure |
| SHA3-256 | 256 bits | 64 | Secure, different internal design |
MD5 vs SHA256: collisions and speed
MD5 is faster than SHA256, and that is about its only advantage. Researchers published MD5 collisions in 2004, and attackers later used them to forge a certificate. Today anyone can create two different files with the same MD5 digest on an ordinary computer.
MD5 still works for catching accidental corruption, such as a broken download. For anything where someone might tamper on purpose, use SHA256.
SHA256 vs SHA512: which should you use?
SHA512 uses 64-bit words, 1024-bit blocks and 80 rounds, and gives a 512-bit digest. On 64-bit processors it can be faster than SHA256 for large inputs, because it processes twice as much data per block. SHA256 gives shorter digests and is more widely expected by tools and protocols. Both are secure; pick SHA256 unless a system asks for SHA512.
SHA256 vs SHA3: what is the difference?
SHA3, standardised in NIST FIPS 202 in 2015, is built on Keccak and a "sponge" construction instead of chained blocks. It was chosen through a public competition as a backup in case SHA-2 were ever broken, which has not happened.
The practical difference is length extension. With SHA256, someone who knows the digest of a secret plus a message can compute the digest of that message with extra data appended, without knowing the secret. SHA3 is not affected. That is why a naive "hash of key plus message" is unsafe with SHA256, and why HMAC exists.
Why is SHA256 alone the wrong tool for storing passwords?
SHA256 was designed to be fast. That is perfect for checking a 2 GB file and terrible for passwords. If a database of plain SHA256 password hashes leaks, attackers can test billions of guesses per second on graphics cards, and common passwords fall almost at once.
Do not store passwords as SHA256(password). Identical passwords get identical hashes, precomputed lookup tables work against it, and every guess is cheap. Use a slow, salted password hashing function instead.
The right tools are built to be slow and salted:
- Argon2id, the current first choice, which also uses lots of memory to slow down graphics cards.
- scrypt and bcrypt, both long-established and widely supported.
- PBKDF2 with HMAC-SHA256 and a high iteration count, when a standards-approved option is required.
The OWASP Password Storage Cheat Sheet lists current recommended settings for each. And the best defence starts before hashing: a long random password from the password generator resists guessing no matter which function stores it.
See the avalanche effect yourselfType a word, change one letter and watch the SHA256 digest changeHow to hash text and files with SHA256 in your browser
The SecretNote hash generator runs entirely in your browser. Your text and files are hashed on your device and never uploaded.
- Open the hash generator and stay on the Text tab.
- Type or paste your input. The SHA-256 digest updates as you type, next to MD5, SHA-1, SHA-224, SHA-384, SHA-512, SHA3-256 and RIPEMD-160.
- Pick the output format: lowercase hex, uppercase hex or Base64.
- Press copy next to the SHA-256 field.
The tool also shows the character and byte count, which helps when a non-ASCII character produces a different digest than you expected.
- Switch to the File tab and drop a file onto the drop zone, or click to choose one.
- The file is read in chunks with a progress bar, then MD5, SHA-1, SHA-256 and SHA-512 digests appear.
- Paste the checksum published by the download page into the verify field. The tool tells you which algorithm matches, or that the file does not match.
- Switch to the Identify tab and paste an unknown hash.
- A 64-character hex string is listed as SHA-256, SHA3-256 or BLAKE2s, since all three produce 32-byte digests.
- Prefixes such as $2b$ or $argon2id$ are recognised as bcrypt or Argon2 password hashes.
Need a keyed signature instead of a plain hash? The HMAC tab takes a secret key and a message and returns HMAC-SHA256 by default, with SHA-1, SHA-224, SHA-384, SHA-512 and MD5 also available.

Get the SHA256 of any text or file in seconds
Hash text as you type, verify a download against its published checksum or sign a message with HMAC-SHA256, all inside your browser.
Frequently asked questions
No. SHA256 is a one-way function with no key, so there is nothing to decrypt. Sites that claim to reverse SHA256 just look the digest up in a table of hashes of common words and passwords. That works only for short or predictable inputs, never for random data or long unique text.
SHA256 always outputs 256 bits, whatever the input size. Hexadecimal writes 4 bits per character, and 256 divided by 4 is 64. The same digest is 32 bytes in raw form, or 44 characters when written in Base64. Only the way it is written changes, never the underlying value.
Yes. No practical collision or preimage attack on SHA256 is known, and NIST still approves it for signatures, certificates and key derivation. Its real weaknesses are situational: it is too fast for password storage, and it allows length extension, which is why secret-keyed uses should go through HMAC-SHA256.
Yes, for anything security related. MD5 collisions can be created on an ordinary computer, so a tampered file can share an MD5 digest with the original. SHA256 has no known practical collisions and a longer 256-bit output. MD5 is only acceptable for spotting accidental corruption where nobody has a reason to cheat.
Not on its own. Plain SHA256 is fast, so attackers who steal the hashes can test billions of guesses per second. Use a slow, salted password hashing function such as Argon2id, scrypt, bcrypt or PBKDF2 with a high iteration count. These are built to make each guess expensive.