What is SHA-256? The Hash Algorithm That Secures Bitcoin and the Internet
Meta Description: Learn how SHA-256 works, why it's secure, and where it's used—from Bitcoin mining to TLS certificates. Complete guide to the world's most important hash algorithm.
Target Keywords: what is SHA256, SHA256 explained, SHA256 algorithm, SHA256 Bitcoin, how SHA256 works
Every Bitcoin transaction. Every HTTPS connection. Every software download verification. They all depend on SHA-256.
This single algorithm, published in 2001, became the foundation of modern digital security. Here's what it does, how it works, and why it matters.
What is SHA-256?
SHA-256 = Secure Hash Algorithm - 256 bit
It's a cryptographic hash function that takes any input and produces a fixed 256-bit (32-byte) output:
Input: "Hello, World!"
SHA-256: dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
That 64-character hexadecimal string is the "digest" or "hash" of the input.
Part of the SHA-2 Family
SHA-256 belongs to the SHA-2 family, designed by the NSA and published by NIST in 2001:
| Algorithm | Output Size | Security (bits) |
|---|---|---|
| SHA-224 | 224 bits | 112 |
| SHA-256 | 256 bits | 128 |
| SHA-384 | 384 bits | 192 |
| SHA-512 | 512 bits | 256 |
| SHA-512/256 | 256 bits | 128 |
SHA-256 is the most widely used member of this family.
Key Properties of SHA-256
1. Deterministic
Same input always produces same output:
SHA256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Always. Forever. On any computer.
2. Fixed-Size Output
No matter the input size—1 byte or 1 terabyte—output is always 256 bits:
SHA256("a") = ca978112...
SHA256(entire_wikipedia_database) = 7f3d2a8b...
Both produce exactly 64 hex characters.
3. Avalanche Effect
Tiny input changes completely transform the output:
SHA256("Hello") = 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
SHA256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Just changing H to h produces a completely different hash. No pattern, no similarity.
4. One-Way Function
You can compute hash from input, but cannot reverse it:
Input → SHA256 → Hash ✓
Hash → ??? → Input ✗
There's no "decrypt" for SHA-256. This is by design.
5. Collision Resistant
Finding two different inputs that produce the same hash is computationally infeasible:
SHA256(input_A) = SHA256(input_B) where A ≠ B
For SHA-256, you'd need ~2^128 operations to find a collision—more energy than the sun produces in its lifetime.
How SHA-256 Works (Simplified)
The Process
- Padding: Add bits to make input length a multiple of 512 bits
- Parsing: Split padded message into 512-bit blocks
- Initialize: Start with 8 fixed 32-bit hash values
- Process: Run each block through 64 rounds of operations
- Output: Final hash values concatenated = 256-bit hash
The Core Operations
Each round uses:
- Bitwise operations: AND, OR, XOR, NOT
- Rotations: Circular bit shifts
- Additions: 32-bit modular addition
- Compression function: Combines current state with input block
These simple operations, repeated precisely, create unpredictable outputs.
Why It's Secure
- Non-linear mixing: Operations combine bits in complex, non-reversible ways
- Diffusion: Each input bit affects many output bits
- Rounds: 64 rounds ensure thorough mixing
- No shortcuts: No known way to compute hash faster than brute force
Where SHA-256 Is Used
Bitcoin and Cryptocurrency
Bitcoin uses SHA-256 for everything:
Mining (Proof of Work):
SHA256(SHA256(block_header)) must start with N zeros
Miners adjust the nonce until the double-SHA-256 meets the difficulty target. This takes massive computation—that's the "work" in proof of work.
Transaction IDs:
TXID = SHA256(SHA256(transaction_data))
Address Generation:
Address = Base58(RIPEMD160(SHA256(public_key)))
TLS/SSL Certificates
When you see the padlock in your browser:
Certificate fingerprint (SHA-256):
B1:BC:96:8B:D4:F4:9D:62:2A:A8:9A:81:F2:15:01:52:A4:1D:82:9C:E6:...
SHA-256 verifies the certificate hasn't been tampered with.
Code Signing
Software publishers sign code with SHA-256:
- Compute SHA-256 of program
- Encrypt hash with private key (signature)
- User verifies: decrypt signature, compare hashes
Microsoft, Apple, and Google require SHA-256 for code signing.
File Integrity
Verify downloads haven't been corrupted or tampered:
ubuntu-24.04.iso SHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Download, compute hash, compare. Match = safe.
Git Commits
Git uses SHA-1 (moving to SHA-256) for commit IDs:
commit 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c
Each commit is identified by the hash of its contents.
Password Hashing (Sort Of)
SHA-256 alone is not suitable for passwords (too fast). But password algorithms build on SHA-256:
- PBKDF2-SHA256: Key derivation using SHA-256
- HMAC-SHA256: Message authentication
SHA-256 vs Other Algorithms
SHA-256 vs MD5
| Feature | MD5 | SHA-256 |
|---|---|---|
| Output | 128 bits | 256 bits |
| Security | ⛔ Broken | ✅ Secure |
| Collisions | Found (seconds) | Infeasible |
| Use in 2026 | Legacy only | Standard |
SHA-256 vs SHA-512
| Feature | SHA-256 | SHA-512 |
|---|---|---|
| Output | 256 bits | 512 bits |
| Security | 128-bit | 256-bit |
| Speed (64-bit) | Baseline | ~1.5x faster |
| Speed (32-bit) | Baseline | ~2x slower |
| Use case | General | Maximum security |
SHA-256 vs SHA-3
| Feature | SHA-256 | SHA-3 |
|---|---|---|
| Design | Merkle–Damgård | Sponge |
| Status | Standard | Standard (backup) |
| Performance | Fast | Slower (software) |
| Adoption | Universal | Growing |
| Purpose | Primary hash | Diversity |
SHA-3 exists as a backup if SHA-2 is ever compromised. For now, SHA-256 remains the standard.
Security Analysis
Current Status: Secure ✅
As of 2026, no practical attacks against SHA-256:
- Preimage attack: Finding input from hash: ~2^256 operations
- Second preimage: Finding collision with specific hash: ~2^256 operations
- Collision attack: Finding any collision: ~2^128 operations
All computationally infeasible with current or foreseeable technology.
Theoretical Concerns
- Quantum computing: Grover's algorithm could reduce collision resistance to ~2^85 operations. Still secure, but SHA-3 provides more margin.
- Length extension attacks: SHA-256 is vulnerable; use HMAC-SHA256 for message authentication.
Future-Proofing
For extreme long-term security:
- Use SHA-512 (more security margin)
- Consider SHA-3 (different design = independent vulnerabilities)
- For passwords, use Argon2 (not raw SHA-256)
SHA-256 in Code
JavaScript
// Browser (SubtleCrypto)
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('');
}
// Node.js
import { createHash } from 'crypto';
const hash = createHash('sha256').update('hello').digest('hex');
Python
import hashlib
message = "hello"
hash = hashlib.sha256(message.encode()).hexdigest()
# 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Command Line
# Linux/macOS
echo -n "hello" | sha256sum
# Windows PowerShell
$bytes = [System.Text.Encoding]::UTF8.GetBytes("hello")
[System.BitConverter]::ToString((New-Object Security.Cryptography.SHA256Managed).ComputeHash($bytes)).Replace("-","").ToLower()
Generate SHA-256 Hashes
Try SHA-256 yourself:
- SHA-256 Generator — Hash any text
- File Hash Checker — Hash any file
- All Hash Generator — Compare multiple algorithms
FAQ
Is SHA-256 encryption?
No. SHA-256 is a hash function, not encryption. It's one-way—you cannot recover the input from the output. Encryption is two-way with a key.
Can SHA-256 be decrypted?
No. There's no key, no decryption. "SHA-256 decrypters" are actually lookup tables that check if your hash matches a known input.
Why does Bitcoin use double SHA-256?
SHA256(SHA256(x)) provides extra protection against length extension attacks and potentially reduces theoretical vulnerabilities. It also aligns with how HMAC works.
Is 256 bits enough security?
Yes. 2^128 collision resistance means even with all computers on Earth working together, finding a collision would take longer than the age of the universe.
Should I use SHA-256 for passwords?
No, not directly. SHA-256 is too fast. Use bcrypt, scrypt, or Argon2 for passwords. They're intentionally slow and include salting.
Related Tools:
- SHA-256 Generator — Generate SHA-256 hashes
- Hash Generator — All hash algorithms
- File Hash Checker — Verify file integrity