Secure Hash Algorithm 256-bit (SHA-256)
SHA-256 is a cryptographic hash function in the SHA-2 family that produces a unique 256-bit (32-byte) deterministic digest from any input data.
SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash function designed by the U.S. National Security Agency (NSA) and published by NIST in 2001 under FIPS PUB 180-4 as part of the SHA-2 family. It computes a fixed-length, deterministic 256-bit (32-byte) digest—typically rendered as a 64-character hexadecimal string—from an arbitrary-sized input stream.
Generate SHA-256, SHA-512, MD5, and HMAC hashes instantly in your browser with our client-side Hash Generator tool.
Technical Specifications at a Glance
| Specification | SHA-256 Details |
|---|---|
| Standard Reference | NIST FIPS PUB 180-4 |
| Output Digest Length | 256 bits (32 bytes / 64 hexadecimal characters) |
| Internal Block Size | 512 bits (64 bytes) |
| Word Size | 32 bits (8 working state variables: $a, b, c, d, e, f, g, h$) |
| Transformation Rounds | 64 rounds |
| Algorithmic Construction | Merkle–Damgård with Davies–Meyer compression function |
| Collision Security | 128 bits ($2^{128}$ operations to find a collision) |
| Pre-image Security | 256 bits ($2^{256}$ operations to invert) |
The 5 Core Cryptographic Properties
To qualify as a secure cryptographic primitive, SHA-256 satisfies five mathematical invariants:
- Deterministic: Any given input produces the identical 64-character hex digest every single time, across every computing platform.
- Pre-image Resistant (One-Way): Given a digest $H$, it is computationally impossible to reconstruct the original input $m$ such that $\text{SHA-256}(m) = H$.
- Second Pre-image Resistant: Given an input $m_1$, it is computationally impossible to find an alternative input $m_2$ such that $\text{SHA-256}(m_1) = \text{SHA-256}(m_2)$.
- Collision Resistant: It is infeasible to find any two arbitrary distinct inputs that yield the identical hash output. No SHA-256 collision has ever been discovered.
- Avalanche Effect: Changing a single bit in the input alters approximately 50% of the output digest bits in an unpredictable manner, completely disguising any relationship between original inputs.
Input: "devflow"
Hash: b873f4b4ce63351ff5606d09c25f4a62174c1737e6f3dfef0b9bb8590c888d30
Input: "Devflow" (Only the first letter capitalized)
Hash: 20bc706c88820c74fbffca4ea45258cf57df6630f5b118b6287e07662c19e34e
Cryptographic Hash Comparison Matrix
| Algorithm | Digest Size | Collision Status | Performance | Security Status |
|---|---|---|---|---|
| MD5 | 128 bits | Broken ($2^{16}$ practical collisions) | Fast | Insecure: Never use for security. |
| SHA-1 | 160 bits | Broken (SHAttered attack 2017) | Fast | Deprecated: Deprecated by NIST & CAs. |
| SHA-256 | 256 bits | Unbroken | Moderate | Recommended Industry Standard. |
| SHA-512 | 512 bits | Unbroken | Fast on 64-bit CPUs | Recommended (High Security). |
| SHA-3 (Keccak) | 256/512 bits | Unbroken (Sponge Construction) | Moderate | Next-Gen: Immune to length extension. |
| BLAKE3 | 256 bits | Unbroken (Merkle Tree) | Ultra-Fast (SIMD) | Excellent for checksums & large files. |
Critical Security Caveat: Password Storage
[!CAUTION] Never store user passwords using raw SHA-256. Modern consumer GPUs can compute over 10 billion SHA-256 hashes per second, allowing attackers to crack password databases via brute-force and rainbow tables in minutes. Always hash passwords with memory-hard, adjustable-cost Key Derivation Functions (KDFs) such as Argon2id, bcrypt, or scrypt.
Code Examples
JavaScript (Web Crypto API in Browser & Node.js)
// Native browser & Node.js crypto.subtle implementation
async function sha256(message) {
const msgBuffer = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
}
sha256("DevFlow Tools").then(console.log);
// Output: 64-character hexadecimal string
Python 3
import hashlib
def get_sha256(text: str) -> str:
return hashlib.sha256(text.encode("utf-8")).hexdigest()
print(get_sha256("DevFlow Tools"))
Frequently Asked Questions
Can SHA-256 be reversed or decrypted?
No. SHA-256 is a one-way mathematical operation, not encryption. Because an input of infinite length (such as a 100 GB file) is compressed into a fixed 256-bit digest, data is intentionally discarded. Reversing the hash to recover the exact input file is mathematically impossible.
Has anyone ever found a SHA-256 collision?
No. Finding a SHA-256 collision requires approximately $2^{128}$ operations due to the birthday paradox. To calculate this would require the continuous energy output of modern civilizations running millions of years.
Why is SHA-256 used in Bitcoin?
Bitcoin uses double SHA-256 (SHA-256(SHA-256(block_header))) for its Proof-of-Work (PoW) consensus mechanism. Because SHA-256 is strictly deterministic and unpredictable, miners must alter a random number (nonce) billions of times until the resulting hash falls below a mathematical target threshold, guaranteeing decentralized network security.
How does SHA-256 differ from HMAC-SHA256?
SHA-256 is an unkeyed hash function that anyone can compute for a given message. In contrast, an HMAC-SHA256 incorporates a secret key into the hash computation, ensuring not only that data wasn't modified, but also that it was authored by someone with the private key.
Interactive Tools for Secure Hash Algorithm 256-bit (SHA-256)
Free, browser-based utilities to test, generate, and inspect Secure Hash Algorithm 256-bit (SHA-256) payloads directly.