What Is SHA-256? How the Secure Hash Algorithm Works and Where It's Used
SHA-256 explained in plain language: what it is, how it works, where it's used (HTTPS, downloads, Bitcoin, HMAC), whether it's still secure, and how to generate a hash.

On this page
Quick answer: SHA-256 is a cryptographic hash function that turns any input — a word, a password, a file or a whole hard drive — into a fixed 256-bit fingerprint, written as 64 hexadecimal characters. The same input always gives the same hash, the tiniest change gives a completely different one, and you can’t reverse the hash to get the input back. That’s why SHA-256 protects SSL certificates, software downloads, digital signatures and Bitcoin.
What is SHA-256?
SHA-256 stands for Secure Hash Algorithm 256-bit. It belongs to the SHA-2 family of hash functions designed by the US National Security Agency and published by NIST (the US National Institute of Standards and Technology) in 2001. The current official specification is FIPS 180-4, the Secure Hash Standard.
A hash function takes data of any size and produces a short, fixed-size value called a hash or digest. Think of it as a digital fingerprint: two different files will (in practice) never share the same fingerprint, and the fingerprint tells you nothing about what the file contains.
What does a SHA-256 hash look like?
Every SHA-256 hash is exactly 64 hexadecimal characters long, no matter how big the input is. Here are three real examples:
| Input | SHA-256 hash |
|---|---|
hello |
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 |
Hello |
185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969 |
| (empty text) | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
Changing just one letter from “hello” to “Hello” produces a completely different hash. This is called the avalanche effect, and it’s one of the properties that makes SHA-256 so useful.
Key properties of SHA-256
- Deterministic — the same input always produces the same hash, on any computer.
- Fixed length — the output is always 256 bits (32 bytes), whether the input is one character or a 50 GB file.
- One-way (pre-image resistant) — given a hash, there is no practical way to work out the original input.
- Collision resistant — it is practically impossible to find two different inputs that produce the same hash.
- Avalanche effect — a one-bit change in the input changes roughly half the bits of the output.
- Fast — computers can calculate SHA-256 very quickly, which is great for checking files but, as we’ll see, a weakness for passwords.
How does SHA-256 work?
You don’t need to understand the maths to use SHA-256, but a high-level picture helps:
- Padding: the message is padded so its length is a multiple of 512 bits. The original message length is added at the end.
- Splitting into blocks: the padded message is divided into 512-bit blocks.
- Initial values: the algorithm starts with eight fixed 32-bit values (derived from the square roots of the first eight prime numbers).
- Compression: each block goes through 64 rounds of bitwise operations — rotations, shifts, AND, XOR and modular addition — mixed with 64 constants (derived from the cube roots of the first 64 primes).
- Chaining: the result of each block feeds into the next one.
- Output: after the last block, the eight 32-bit values are joined together to form the final 256-bit hash.
This block-by-block chaining design is known as the Merkle–Damgård construction.
Where is SHA-256 used?
1. SSL/TLS certificates and HTTPS
When you see the padlock in your browser, SHA-256 is almost certainly involved. Certificate authorities sign website certificates using SHA-256, and TLS uses it to check that data hasn’t been tampered with in transit.
2. File integrity and software downloads
Many software publishers list a SHA-256 checksum next to each download. After downloading, you calculate the file’s hash and compare it. If it matches, the file is exactly what the publisher released, with no corruption or malware injected along the way.
3. Digital signatures and code signing
Digital signatures don’t sign the whole document; they sign its SHA-256 hash. Operating systems use the same idea to verify that apps and updates really come from their developers.
4. Blockchain and Bitcoin
Bitcoin uses SHA-256 (applied twice) to link blocks together and for its proof-of-work mining. Changing a single transaction would change the block’s hash and break the chain, which makes the history tamper-evident.
5. Message authentication (HMAC-SHA256)
HMAC-SHA256 combines SHA-256 with a secret key. APIs and payment gateways use it to sign webhooks and requests, so the receiver can confirm a message came from the right sender and wasn’t altered.
6. Storing one-time codes and tokens
Well-built applications never store sensitive codes in plain text. For example, Afojet AuthTick stores WhatsApp OTP codes hashed, so even if the database leaked, the codes could not be read.
Is SHA-256 good for storing passwords?
Not on its own. SHA-256 is designed to be fast, and that’s exactly what attackers want: modern graphics cards can try billions of SHA-256 guesses per second against a stolen password database. Plain SHA-256 password hashes are also vulnerable to pre-computed “rainbow tables” if no salt is used.
For passwords, use a slow, salted algorithm built for the job:
- Argon2id — the modern recommended choice.
- bcrypt — widely supported and used by PHP’s
password_hash()by default. - PBKDF2-HMAC-SHA256 — uses SHA-256 internally, but repeats it many thousands of times with a salt.
WordPress, for example, handles password hashing for you, so you should never roll your own SHA-256 password storage in a plugin or theme.
Is SHA-256 still secure in 2026?
Yes. There is no known practical attack that finds collisions or reverses SHA-256. Its older cousin SHA-1 was publicly broken in 2017 when researchers produced two different PDF files with the same SHA-1 hash, and MD5 has been broken for much longer, which is why both should no longer be used for security.
Two points worth knowing:
- Length-extension attacks: because of its Merkle–Damgård design, using
SHA256(secret + message)as a signature is unsafe. Use HMAC-SHA256 instead. - Quantum computers: Grover’s algorithm could in theory reduce SHA-256’s pre-image strength from 256 bits to about 128 bits, which is still considered secure.
SHA-256 vs MD5 vs SHA-1 vs SHA-3
| Algorithm | Output size | Status |
|---|---|---|
| MD5 | 128 bits | Broken — don’t use for security |
| SHA-1 | 160 bits | Broken (collision shown in 2017) |
| SHA-256 | 256 bits | Secure and widely used |
| SHA-512 | 512 bits | Secure; often faster on 64-bit CPUs |
| SHA-3 (SHA3-256) | 256 bits | Secure; different internal design, not vulnerable to length extension |
How to generate a SHA-256 hash
On Linux
sha256sum filename.zip
On macOS
shasum -a 256 filename.zip
On Windows (Command Prompt or PowerShell)
certutil -hashfile filename.zip SHA256Get-FileHash filename.zip -Algorithm SHA256
In PHP
echo hash('sha256', 'hello');
For a keyed signature: hash_hmac('sha256', $message, $secret_key);
In JavaScript (browser)
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode('hello'));
Best practices for using SHA-256
- Use it for integrity — checksums, file verification, digital signatures and data fingerprints.
- Use HMAC-SHA256 for authentication — never just hash a secret joined to a message.
- Don’t use plain SHA-256 for passwords — use Argon2id, bcrypt or PBKDF2.
- Compare hashes safely — in code, use constant-time comparison such as PHP’s
hash_equals()to avoid timing attacks. - Retire MD5 and SHA-1 — replace them with SHA-256 or stronger anywhere security matters.
- Get checksums from a trusted source — a hash only helps if it comes from the publisher over HTTPS, not from the same place a tampered file might be.
FAQ
Can SHA-256 be decrypted?
No. SHA-256 is a hash, not encryption, so there is no key and nothing to decrypt. “SHA-256 decrypter” websites only look up hashes of common words they have already calculated, which is why short or common inputs are unsafe.
How long is a SHA-256 hash?
256 bits, which is 32 bytes or 64 hexadecimal characters.
Is SHA-256 the same as SHA-2?
SHA-256 is one member of the SHA-2 family. The family also includes SHA-224, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.
Can two files have the same SHA-256 hash?
In theory yes, because there are infinitely many possible inputs and a fixed number of hashes. In practice, no one has ever found a SHA-256 collision, and finding one is far beyond current computing power.
Is SHA-256 encryption?
No. Encryption is two-way: you can decrypt with the right key. Hashing is one-way: you can only check whether an input produces the same hash.
Conclusion
SHA-256 is one of the building blocks of modern cyber security. It keeps HTTPS connections trustworthy, proves that downloads haven’t been tampered with, secures digital signatures and powers Bitcoin. Use it for integrity and, through HMAC, for authentication — but pair it with a dedicated password-hashing algorithm when you store passwords.
Building a WordPress or WooCommerce site and want security built in? Explore Afojet’s plugins, including OTP login with hashed codes and rate limits.
Keep reading
View all →
WhatsApp APIMeta Introduces a New WhatsApp Business Account Structure: WAAC and Messaging Accounts Explained (2026)
WooCommerceHow to Reduce Fake COD Orders in WooCommerce with Free OTP Verification
HostingVPS Server Reboot Issue: Root Cause & Permanent Fix
Unexpected server reboots and websites becoming inaccessible are among the most frustrating problems for VPS users. Many VPS environments experience random downtime, Apache freezes, or sudden performance issues without clear error messages.
Comments
No comments yet. Be the first!
Leave a comment