ToolForge
Browse All 79 Tools

Categories

SecurityUpdated 2026Code Examples

MD5 vs SHA-256 — Which Hash Algorithm Should You Use?

You need to verify a downloaded file, store a password, or generate a checksum. Should you use MD5 or SHA-256? This complete md5 vs sha256 comparison covers security, speed, output differences, and real-world use cases — updated for 2026.

📅 Updated: June 2026⏱️ Read time: 18 minutes📊 10 sections · 10 FAQs
Written by ToolForge Team
Updated June 2026
18 min read
Reviewed for accuracy

🔐 Try it yourself

Paste any text into our free Hash Generator to see MD5, SHA-256, and SHA-512 outputs side by side. No signup required.

What Is a Hash Function?

A hash function is a one-way mathematical algorithm that converts any input — a word, a file, an entire database — into a fixed-length string of characters called a hash, digest, or checksum. Think of it as a fingerprint for data: every unique input produces a unique fingerprint, and the same input always produces the same fingerprint.

Hash functions are fundamentally different from encryption. Encryption is reversible — you can decrypt ciphertext back to plaintext with the right key. Hashing is one-way by design — you cannot mathematically recover the original input from its hash.

Deterministic

The same input always produces the same hash output, on any machine, at any time.

Fixed Output Length

No matter the input size (1 byte or 1 GB), the output hash is always the same length.

Avalanche Effect

Changing a single character in the input completely changes the hash output.

Pre-image Resistance

Given a hash, it is computationally infeasible to find the original input.

Collision Resistance

It should be infeasible to find two different inputs that produce the same hash.

One-Way Function

The hash cannot be "reversed" — the original data cannot be recovered from the digest alone.

MD5 and SHA-256 are both hash functions — they share all these properties in theory. The critical difference is that MD5's collision resistance has been broken, while SHA-256's remains intact.

Input: "Hello World"
MD5: b10a8db164e0754105b7a99be72e3fe5
SHA-256: a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

Notice that even for the same two-word input, MD5 produces 32 hex characters (128 bits) while SHA-256 produces 64 hex characters (256 bits). For a deeper look at how hashing works in practice, try our Hash Generator which shows MD5, SHA-1, SHA-256, SHA-384, and SHA-512 outputs in real-time.

What Is MD5?

MD5 (Message Digest Algorithm 5) was designed by cryptographer Ronald Rivest at MIT in 1991 as an improvement over his earlier MD4 algorithm. It was widely adopted throughout the 1990s and 2000s for file verification, password storage, and digital signatures.

128-bit

Output Length

32 hex characters

1991

Year Designed

Ronald Rivest, MIT

2004

Collision Found

Wang Xiaoyun

Security Status

Cryptographically broken

MD5 processes input in 512-bit blocks and uses four rounds of simple bitwise operations (AND, OR, XOR, NOT) to produce its 128-bit output. These simple operations made MD5 extremely fast on 1990s hardware — which was the goal. Speed, however, became its downfall as a security algorithm.

In 2004, Chinese cryptographer Wang Xiaoyun demonstrated a practical collision attack — the ability to generate two different inputs with the same MD5 hash. By 2008, researchers used this technique to forge a fraudulent SSL certificate that appeared to be signed by a legitimate Certificate Authority. In 2012, the Flame malware used an MD5 collision to forge Windows Update certificates, allowing malicious code to appear as legitimate Microsoft updates.

⚠️ Critical Warning

MD5 should NOT be used for passwords, digital signatures, TLS certificates, code signing, or any security-sensitive application. Its collision resistance is broken and cannot be repaired.

MD5 is still acceptable for non-security tasks where collision resistance is irrelevant:

  • Cache key generation (even distribution matters, not uniqueness guarantees)
  • Data deduplication (approximate matching, not security verification)
  • Partitioning data across servers in a distributed system
  • Non-security file identification in trusted internal systems
  • Legacy system compatibility where SHA-256 migration is not yet possible

What Is SHA-256?

SHA-256 (Secure Hash Algorithm 256-bit) is part of the SHA-2 family, designed by the United States National Security Agency (NSA) and published by NIST (National Institute of Standards and Technology) in 2001. It replaced SHA-1, which itself replaced the original SHA-0 standard.

256-bit

Output Length

64 hex characters

2001

Year Published

NSA / NIST

2^128

Collision Cost

Computationally infeasible

Security Status

Industry standard 2026

SHA-256 processes data in 512-bit blocks across 64 rounds of operations — far more complex than MD5's four rounds. This complexity is intentional: it makes SHA-256 significantly harder to attack while still being fast enough for practical use.

As of 2026, no practical collision attack has ever been demonstrated against SHA-256. The theoretical cost of finding a collision requires approximately 2128 operations — a number so large that even all the computers on Earth running for billions of years could not find one.

SHA-256 is the algorithm behind some of the most critical systems in modern computing:

Bitcoin & Blockchain

Core proof-of-work algorithm. Mining involves finding a SHA-256 hash below a target value.

🔒

TLS/SSL Certificates

Required for HTTPS. All modern web certificates use SHA-256 signatures.

✍️

Digital Signatures

PKI infrastructure, code signing, document authentication.

🔑

HMAC Authentication

HMAC-SHA256 is the industry standard for API authentication and JWT tokens.

📦

Package Integrity

npm, pip, apt, and every major package manager uses SHA-256 checksums.

🏛️

Compliance Standards

Required by FIPS 140-2, PCI DSS, and most government security frameworks.

MD5 vs SHA-256 — Complete Comparison

Here is a side-by-side comparison of every meaningful difference between MD5 and SHA-256. Use this as a quick reference when choosing between them.

FeatureMD5SHA-256
Output Length128 bits (32 hex chars)256 bits (64 hex chars)
Year Introduced19912001
DesignerRonald RivestNSA / NIST
Collision Resistant❌ No (broken since 2004)✅ Yes
Pre-image ResistantWeakened✅ Yes
SpeedFasterSlightly slower
Hardware AccelerationNo dedicated CPU extensionSHA-NI (Intel/AMD, ARM)
Security Rating 2026❌ Deprecated for security✅ Industry standard
Bitcoin/BlockchainNot used✅ Core algorithm
TLS Certificates❌ Deprecated since 2015✅ Required standard
Password Hashing❌ Never use directly❌ Never use directly (use bcrypt/Argon2)
File ChecksumsAcceptable (non-security)✅ Recommended
FIPS 140-2 Compliant❌ No✅ Yes
PCI DSS Approved❌ No✅ Yes

Why MD5 Is No Longer Secure

Understanding why MD5 is broken requires understanding what a collision attack actually means in practice — and the real-world damage it has already caused.

MD5 Collision Attacks Explained

A collision occurs when two different inputs produce the same hash output. For a secure hash function, finding a collision should require testing approximately 264 inputs for MD5 (birthday bound). In 2004, Wang Xiaoyun's team demonstrated a method requiring only about 239 operations — achievable in minutes on consumer hardware.

What does this mean practically? An attacker can craft two different files — say, a benign document and a malicious executable — that share the same MD5 hash. If a system uses MD5 to verify file integrity, it will accept the malicious file as authentic. This is not theoretical:

2004

Wang Xiaoyun demonstrates first practical MD5 collision, costing ~2^39 operations instead of ~2^64.

2008

Security researchers create a rogue CA certificate using an MD5 collision, enabling them to impersonate any HTTPS website.

2012

Flame malware forges Windows Update certificates via MD5 collision, distributing state-sponsored malware as legitimate Microsoft updates.

2015

All major browsers and certificate authorities deprecate MD5 in TLS certificates. NIST officially withdraws MD5 for digital signatures.

Is SHA-256 Truly Secure?

No practical attack against SHA-256 has ever been demonstrated. The birthday bound for SHA-256 collisions is approximately 2128 operations — a number that exceeds the estimated number of atoms in the observable universe. Even with all computational power on Earth dedicated to finding a SHA-256 collision, it would not succeed within any practical timeframe.

The one legitimate concern about SHA-256's long-term security is quantum computing. Grover's algorithm, running on a sufficiently powerful quantum computer, could reduce the effective security of SHA-256 from 256-bit to 128-bit equivalent. However, 128-bit security is still above the minimum recommended threshold, and quantum computers capable of this attack are estimated to be at least 15-20 years from practical reality. NIST has published post-quantum standards as a proactive measure, but SHA-256 remains safe for current and near-future use.

MD5 vs SHA-256 — Speed and Performance

MD5 is generally faster than SHA-256 because it processes data in simpler operations and produces a shorter output. The difference is real but often irrelevant for practical applications.

MetricMD5SHA-256
Throughput (modern CPU, software)~2.5 GB/s~1.5 GB/s
Throughput (SHA-NI hardware acceleration)Not available~4–8 GB/s
Hash 1 KB of data~0.4 µs~0.7 µs (software) / ~0.1 µs (SHA-NI)
JavaScript (Web Crypto API)Not natively availableNative via crypto.subtle

The key insight: modern Intel and AMD processors since ~2013 include SHA-NI (SHA New Instructions) — dedicated hardware instructions that accelerate SHA-256 to speeds that exceed MD5 in software. ARM processors in recent Apple Silicon and Android devices include similar extensions.

Bottom Line on Speed

The speed difference between MD5 and SHA-256 is negligible for the vast majority of applications. Hashing a 10 MB file takes milliseconds either way. Only ultra-high-throughput systems processing terabytes per second need to consider algorithm speed — and at that scale, SHA-256 with SHA-NI is typically faster than software MD5 anyway.

Test both algorithms yourself with our Hash Generator — it shows all hash outputs instantly.

SHA-1, SHA-256, SHA-384, SHA-512 — Which to Choose?

The SHA-2 family includes multiple variants. Here is where each stands in 2026:

SHA-1160-bit❌ Deprecated

Google's SHAttered attack (2017) demonstrated a practical SHA-1 collision using 6,500 CPU-years of computation — now achievable for under $75,000. Do not use SHA-1 for any purpose. All major browsers and certificate authorities removed SHA-1 support.

SHA-256256-bit✅ Recommended

The current standard. Widely supported, hardware-accelerated, and required by most compliance frameworks. Use SHA-256 as your default choice for everything from file checksums to HMAC authentication.

SHA-384384-bit✅ Specialized use

A truncated version of SHA-512, often used in TLS cipher suites. Provides slightly larger security margin than SHA-256 at a small performance cost. Choose if required by a specific protocol or compliance standard.

SHA-512512-bit✅ High-throughput

Faster than SHA-256 on 64-bit processors due to wider registers, despite producing a larger output. Provides a larger security margin. Use for performance-sensitive 64-bit environments or when extra security headroom is desired.

SHA-3 (Keccak)Variable✅ Alternative standard

A completely different algorithm design from SHA-2, selected as an alternative standard by NIST in 2015. Provides insurance if a theoretical weakness is ever found in SHA-2. The SHA-2 family remains dominant in practice.

How to Generate Hashes — Code Examples

Here are SHA-256 hash generation examples in five common languages. For quick one-off hashing without writing code, use our browser-based Hash Generator.

JavaScript (Node.js)

const crypto = require('crypto');

// SHA-256
const sha256 = crypto.createHash('sha256').update('Hello World').digest('hex');
console.log('SHA-256:', sha256);
// a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

// MD5 (not recommended for security)
const md5 = crypto.createHash('md5').update('Hello World').digest('hex');
console.log('MD5:', md5);
// b10a8db164e0754105b7a99be72e3fe5

JavaScript (Browser — Web Crypto API)

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('Hello World').then(hash => console.log(hash));
// a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

// Note: Web Crypto API does NOT support MD5 natively

Python

import hashlib

# SHA-256
sha256_hash = hashlib.sha256("Hello World".encode()).hexdigest()
print("SHA-256:", sha256_hash)
# a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

# SHA-512
sha512_hash = hashlib.sha512("Hello World".encode()).hexdigest()
print("SHA-512:", sha512_hash)

# MD5 (use usedforsecurity=False to suppress deprecation warning in Python 3.9+)
md5_hash = hashlib.md5("Hello World".encode(), usedforsecurity=False).hexdigest()
print("MD5:", md5_hash)

PHP

<?php
// SHA-256
$sha256 = hash('sha256', 'Hello World');
echo "SHA-256: " . $sha256 . PHP_EOL;
// a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

// SHA-512
$sha512 = hash('sha512', 'Hello World');
echo "SHA-512: " . $sha512 . PHP_EOL;

// MD5 (for non-security use only)
$md5 = md5('Hello World');
echo "MD5: " . $md5 . PHP_EOL;
?>

Bash (Linux / macOS)

# SHA-256 (standard on all systems)
echo -n "Hello World" | sha256sum

# SHA-512
echo -n "Hello World" | sha512sum

# MD5
echo -n "Hello World" | md5sum

# Hash a file
sha256sum myfile.tar.gz
# Outputs: <hash>  myfile.tar.gz

When to Use Which Algorithm

Use this table as a reference when choosing a hashing algorithm for a specific task.

Use CaseRecommendedWhy
File integrity verificationSHA-256Collision-resistant, widely supported by download tools
Non-security cache keysMD5 (acceptable)Fast, even distribution; collisions irrelevant for caching
Password storagebcrypt / Argon2 / scryptPurpose-built: includes salting + configurable work factor
Digital signaturesSHA-256 or SHA-512Required by PKI, X.509, and code signing standards
Blockchain / cryptocurrencySHA-256Bitcoin standard; well-audited for this use case
API authentication (HMAC)SHA-256HMAC-SHA256 is the JWT and AWS Signature standard
TLS certificatesSHA-256Required by all browsers; SHA-1 and MD5 are rejected
Data deduplicationSHA-256 or MD5Either works; SHA-256 eliminates remote collision risk
Git commit hashingSHA-1 → SHA-256 migrationGit is actively migrating from SHA-1 to SHA-256

❌ Password Hashing Warning

Never use MD5, SHA-1, SHA-256, or SHA-512 directly for storing passwords. These algorithms are fast by design, which makes them easy to brute-force. An attacker with a modern GPU can test billions of SHA-256 hashes per second. Always use bcrypt, Argon2, or scrypt — they are intentionally slow and include built-in salting.

Frequently Asked Questions

Is MD5 still safe to use in 2026?
MD5 is not safe for any security purpose. It has been cryptographically broken since 2004 and practical collision attacks are trivial on modern hardware. MD5 is still acceptable for non-security tasks like cache key generation, data deduplication, and quick file identification in trusted environments — but SHA-256 is recommended even for these cases because the performance difference is negligible on modern processors.
Which is faster — MD5 or SHA-256?
MD5 is generally 40–60% faster than SHA-256 in software. However, modern CPUs with SHA-NI hardware extensions accelerate SHA-256 to speeds that can exceed software MD5. For most applications — hashing files under 100 MB — the difference is microseconds and completely irrelevant.
Can MD5 hashes be reversed or decrypted?
No. Hash functions are one-way by design. "MD5 decryption" tools online work by comparing hashes against pre-computed rainbow tables, not reversing the algorithm. They only work for common passwords and short strings. This is why salting is critical — adding a unique salt makes rainbow table attacks impossible.
What hash algorithm does Bitcoin use?
Bitcoin uses double SHA-256 (hashing the data twice). SHA-256 was chosen for its collision resistance, well-audited security properties, and efficient hardware implementation. Bitcoin ASICs are essentially dedicated SHA-256 accelerators.
Should I use SHA-256 or SHA-512?
SHA-256 is the standard default choice — widely supported, hardware-accelerated, and required by most compliance frameworks. Use SHA-512 if you are on a 64-bit server processing very large volumes of data (SHA-512 is actually faster than SHA-256 on 64-bit hardware because it uses 64-bit operations internally) or if your compliance requirements call for it.
Why is MD5 still used if it is broken?
MD5 is still used in legacy systems, protocol specifications, and non-security applications where collision resistance is irrelevant (e.g., cache keys, deduplication). The cost of migrating deeply embedded systems is high and the urgency varies depending on whether the use case is security-sensitive. Many file download pages still publish both MD5 and SHA-256 checksums for backward compatibility.
What is the difference between hashing and encryption?
Hashing is one-way: data in, fixed-length digest out, no way back. Encryption is two-way: data is transformed with a key and can be reversed with the correct key. Hashing is for verification (did this file change? is this the correct password?). Encryption is for confidentiality (keep this data secret during transmission or storage).
What is a hash collision?
A collision is when two different inputs produce the same hash output. For MD5, practical collision attacks have been demonstrated repeatedly since 2004. For SHA-256, no practical collision has ever been found — the theoretical minimum cost is ~2^128 operations, computationally infeasible for any foreseeable technology.
What hash algorithm should I use for passwords?
Never use raw MD5, SHA-1, SHA-256, or SHA-512 for passwords. Use bcrypt (most widely adopted), Argon2 (recommended for new systems, winner of the Password Hashing Competition), or scrypt. These algorithms are designed to be slow and include configurable work factors you can increase as hardware improves.
Will quantum computers break SHA-256?
Grover's algorithm on a quantum computer could theoretically reduce SHA-256's security from 256-bit to 128-bit equivalent. 128-bit security is still considered safe — above NIST's minimum threshold. Practical quantum computers capable of this attack are estimated to be 15–20+ years away. NIST has published post-quantum standards proactively, but SHA-256 is not an immediate concern.

Try It Yourself

Generate MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashes instantly with our free Hash Generator. Paste any text or drop a file — all processing happens in your browser and no data is ever sent to a server.

Advertisement