Skip to main content

Command Palette

Search for a command to run...

Back to Blog
Guides

Understanding Hash Functions: MD5, SHA, and Security Best Practices

Learn how hash functions work, the differences between MD5, SHA-1, SHA-256, and SHA-512, and when to use each. Includes security guidance and practical examples.

JumpTools Team
February 2, 2026
9 min read
hashmd5sha256securitycryptographychecksums

Understanding Hash Functions: MD5, SHA, and Security Best Practices

TL;DR

Hash functions convert data of any size into a fixed-size string (digest). MD5 (128-bit) and SHA-1 (160-bit) are deprecated for security but still used for checksums. SHA-256 (256-bit) and SHA-512 (512-bit) are current standards. Use SHA-256+ for security-sensitive applications; MD5/SHA-1 only for non-security checksums. For passwords, use specialized algorithms like bcrypt or Argon2, not plain hashes. Key Facts:

  • MD5 produces a 32-character hex string (128 bits)
  • SHA-256 produces a 64-character hex string (256 bits)
  • Collision attacks make MD5 and SHA-1 unsuitable for security
  • Hashing is one-way; you cannot "decrypt" a hash
---

What is a Hash Function?

A cryptographic hash function is a mathematical algorithm that takes input data of any size and produces a fixed-size output (called a digest, hash, or checksum). Hash functions have these properties:

Core Properties

PropertyDescription
DeterministicSame input always produces same output
Fixed outputOutput size is constant regardless of input size
One-wayCannot reverse the hash to get original data
Avalanche effectSmall input change = completely different output
Collision resistantHard to find two inputs with same hash

Example

Input: "Hello"
MD5:    8b1a9953c4611296a827abf8c47804d7

Input: "hello" (lowercase h) MD5: 5d41402abc4b2a76b9719d911017c592

One character change = completely different hash

Generate hashes: Free Hash Generator →

---

Common Hash Algorithms

MD5 (Message Digest 5)

SpecificationValue
Output size128 bits (32 hex chars)
Created1991
StatusDeprecated for security
SpeedVery fast
Example: d41d8cd98f00b204e9800998ecf8427e (empty string) Use cases today:
  • File integrity checksums (non-security)
  • Cache keys
  • Deduplication
DO NOT use for: Password storage, digital signatures, security certificates.

SHA-1 (Secure Hash Algorithm 1)

SpecificationValue
Output size160 bits (40 hex chars)
Created1995
StatusDeprecated for security
SpeedFast
Example: da39a3ee5e6b4b0d3255bfef95601890afd80709 (empty string)

SHA-1 collision was demonstrated in 2017 (SHAttered attack). Major browsers and CAs have deprecated SHA-1 certificates.

SHA-256 (SHA-2 Family)

SpecificationValue
Output size256 bits (64 hex chars)
Created2001
StatusCurrent standard
SpeedModerate
Example: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 (empty string) Use cases:
  • SSL/TLS certificates
  • Code signing
  • Blockchain (Bitcoin)
  • File verification
  • Digital signatures

SHA-512 (SHA-2 Family)

SpecificationValue
Output size512 bits (128 hex chars)
Created2001
StatusCurrent standard
SpeedFaster than SHA-256 on 64-bit systems
Use cases:
  • High-security applications
  • When longer hash is preferred
  • 64-bit optimized systems

SHA-3 (Keccak)

SpecificationValue
Output size224/256/384/512 bits
Created2015
StatusLatest standard
SpeedComparable to SHA-2
SHA-3 uses a completely different internal structure (sponge construction) than SHA-2. It's a backup if SHA-2 is ever compromised.

---

Comparison Table

AlgorithmOutput SizeSecuritySpeedUse Case
MD5128 bitsBrokenFastestChecksums only
SHA-1160 bitsBrokenFastLegacy systems
SHA-256256 bitsSecureModerateGeneral security
SHA-512512 bitsSecureFast (64-bit)High security
SHA-3VariableSecureModerateFuture-proofing
---

Practical Use Cases

1. File Integrity Verification

When downloading software, verify the file wasn't corrupted or tampered with:

Linux/Mac

sha256sum ubuntu.iso

Compare with published hash on website

Windows (PowerShell)

Get-FileHash ubuntu.iso -Algorithm SHA256

2. Data Deduplication

// Hash file contents to detect duplicates
const hash1 = sha256(file1Contents);
const hash2 = sha256(file2Contents);
if (hash1 === hash2) {
  console.log('Files are identical');
}

3. Cache Keys

// Generate cache key from request parameters
const cacheKey = md5(JSON.stringify(requestParams));
const cached = cache.get(cacheKey);

4. Commit Identifiers (Git)

Git uses SHA-1 for commit hashes:

commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0

5. Blockchain

Bitcoin uses double SHA-256 for mining and block verification:

blockHash = SHA256(SHA256(blockHeader))

---

Password Hashing: Special Considerations

Why Plain Hashes Are NOT Enough

Password: "password123"
SHA-256:  ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f

Problem: Same password = same hash Attackers use precomputed "rainbow tables" to crack common passwords

What to Use Instead

AlgorithmPurposeNotes
bcryptPassword hashingBuilt-in salt, adjustable cost
Argon2Password hashingWinner of PHC, memory-hard
scryptPassword hashingMemory-hard
PBKDF2Key derivationOlder but widely supported
Key features for password hashing:
  1. Salt - Random data added to prevent rainbow tables
  2. Cost factor - Adjustable slowness to resist brute force
  3. Memory hardness - Requires significant RAM (Argon2, scrypt)

Example with bcrypt

const bcrypt = require('bcrypt');

// Hashing a password const password = 'userPassword123'; const saltRounds = 10; const hash = await bcrypt.hash(password, saltRounds); // Result: $2b$10$N9qo8uLOickgx2ZMRZoMye...

// Verifying a password const isMatch = await bcrypt.compare(password, hash);

---

Security Best Practices

DO:

  1. Use SHA-256 or SHA-512 for general cryptographic purposes
  2. Use bcrypt/Argon2 for password storage
  3. Use HMAC when you need keyed hashing
  4. Verify file hashes before running downloaded software
  5. Keep updated on algorithm deprecations

DON'T:

  1. Don't use MD5/SHA-1 for security-sensitive applications
  2. Don't store plain hashes of passwords
  3. Don't create your own hash functions
  4. Don't assume hashing = encryption (hashing is one-way)
  5. Don't ignore salt when hashing passwords
---

Hashing in Code

JavaScript (Browser)

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('');
}

const hash = await sha256('Hello World'); // "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"

Node.js

const crypto = require('crypto');

const hash = crypto.createHash('sha256') .update('Hello World') .digest('hex');

Python

import hashlib

hash = hashlib.sha256(b'Hello World').hexdigest()

PHP

$hash = hash('sha256', 'Hello World');

---

HMAC: Keyed Hashing

HMAC (Hash-based Message Authentication Code) adds a secret key to the hashing process, providing both integrity and authentication.
const crypto = require('crypto');

const hmac = crypto.createHmac('sha256', 'secretKey') .update('message') .digest('hex');

Use HMAC when:
  • Verifying API requests
  • Creating secure tokens
  • Message authentication
  • Webhook signatures
---

Hash Collisions Explained

A collision occurs when two different inputs produce the same hash output.

MD5 Collision Example

Researchers have created two different PDF files with identical MD5 hashes. This is why MD5 cannot be trusted for security.

Collision Resistance Levels

AlgorithmCollision Found?Year
MD5Yes2004
SHA-1Yes2017
SHA-256No-
SHA-512No-
---

Quick Reference

When to Use Each Algorithm

ScenarioRecommended
File checksums (non-security)MD5 or SHA-256
Software verificationSHA-256
Password storagebcrypt or Argon2
API authenticationHMAC-SHA256
SSL/TLS certificatesSHA-256+
Blockchain/cryptoSHA-256 or SHA-3
Git commitsSHA-1 (legacy)

Free Tools

Generate and verify hashes instantly:

---

Conclusion

Hash functions are fundamental to modern security and data integrity. While MD5 and SHA-1 served us well historically, they should only be used for non-security purposes today. For any security-sensitive application, use SHA-256 or stronger. For passwords specifically, always use specialized algorithms like bcrypt or Argon2. Key takeaways:

  1. Hashing is one-way - you cannot "unhash"
  2. MD5/SHA-1 are broken for security
  3. SHA-256 is the current standard
  4. Use bcrypt/Argon2 for passwords, not plain hashes
  5. Always verify downloaded files with their published hashes
Generate hashes now: Hash Generator →