Cryptographic hash functions are fundamental to modern software security. They verify file integrity, secure passwords, validate data, and power blockchain technology. This guide explains how hashing works, compares the major algorithms, and covers best practices for developers and system administrators.
A hash function takes an input of any size and produces a fixed-length output (the "hash" or "digest"). Good hash functions have three key properties:
Input: "Hello, World!"
MD5: 65a8e27d8879283831b664bd8b7f0ad4
SHA-1: 0a0a9f2a6772942557ab5355d76af442f8f65e01
SHA-256: dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
SHA-512: 374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc...
| Algorithm | Output Size | Speed | Security | Status |
|---|---|---|---|---|
| MD5 | 128 bits (32 hex) | Very fast | Broken | Do not use for security |
| SHA-1 | 160 bits (40 hex) | Fast | Broken | Deprecated since 2017 |
| SHA-256 | 256 bits (64 hex) | Moderate | Strong | Current standard |
| SHA-512 | 512 bits (128 hex) | Moderate | Strong | Maximum security |
MD5 was designed in 1991 and produces a 128-bit hash. It was widely used for checksums and integrity verification. However, researchers demonstrated practical collision attacks in 2004, and MD5 should no longer be used for any security-sensitive purpose.
# Generating an MD5 hash
echo -n "devtoolkit" | md5sum
# Result: 7d7e8b1c... (32 hex characters)
Still acceptable for: Non-security checksums (e.g., comparing file versions, cache keys, deduplication). Many legacy systems still use MD5 for these purposes.
Not acceptable for: Passwords, digital signatures, certificate verification, anything where collision resistance matters.
SHA-256 (part of the SHA-2 family) produces a 256-bit hash and is the most widely recommended hash function today. It powers Bitcoin, TLS certificates, and most integrity verification systems.
# Generating a SHA-256 hash
echo -n "devtoolkit" | sha256sum
# Result: a3f2b8c9... (64 hex characters)
# Verifying a file download
sha256sum ubuntu-24.04-desktop-amd64.iso
# Compare with the checksum on the download page
When you download software, the publisher often provides a SHA-256 checksum. You can verify the download was not corrupted or tampered with:
# Linux/macOS
sha256sum downloaded-file.tar.gz
# Compare output with the published hash
# Windows (PowerShell)
Get-FileHash .\downloaded-file.tar.gz -Algorithm SHA256
# Python
import hashlib
with open("file.tar.gz", "rb") as f:
print(hashlib.sha256(f.read()).hexdigest())
DevToolKit's Hash Generator lets you quickly compute hashes for text without needing a terminal.
This is perhaps the most important section of this guide. Never store passwords using MD5, SHA-1, or even SHA-256 directly. General-purpose hash functions are too fast, making them vulnerable to brute-force and rainbow table attacks.
| Algorithm | Recommended? | Notes |
|---|---|---|
| bcrypt | Yes | Adaptive cost factor, widely supported |
| Argon2id | Yes (best) | Winner of Password Hashing Competition (2015) |
| scrypt | Yes | Memory-hard, good alternative to Argon2 |
| PBKDF2 | Acceptable | NIST-approved, use with high iteration count |
| SHA-256 (raw) | No | Too fast, vulnerable to GPU attacks |
| MD5 (raw) | Never | Billions of hashes per second on modern GPUs |
# Python - correct password hashing
import bcrypt
hashed = bcrypt.hashpw(b"my_password", bcrypt.gensalt(rounds=12))
# Node.js
const bcrypt = require('bcrypt');
const hash = await bcrypt.hash("my_password", 12);
# WRONG - never do this:
# hashlib.sha256(b"my_password").hexdigest() -- TOO FAST!
Generate strong passwords with the Password Generator and always use proper password hashing in your applications.
HMAC combines a hash function with a secret key to produce an authenticated hash. It is used in JWT signatures, API authentication, and webhook verification:
# HMAC-SHA256 example
import hmac, hashlib
signature = hmac.new(b"secret_key", b"message", hashlib.sha256).hexdigest()
# Webhook verification (e.g., GitHub, Stripe)
expected = hmac.new(secret, payload, hashlib.sha256).hexdigest()
if hmac.compare_digest(expected, received_signature):
# Valid webhook
No. Hash functions are one-way. You cannot reverse SHA-256 or MD5 to recover the input. Attackers use precomputed tables (rainbow tables) or brute force to find inputs that match a target hash, which is why strong passwords matter.
No. SHA-256 is fast enough for checksums and provides actual collision resistance. MD5 is slightly faster but offers no security guarantee. The performance difference is negligible for most use cases.
SHA-512 is actually faster than SHA-256 on 64-bit processors. Use it when you need a longer hash output or when working with security-critical applications that benefit from the extra bit length.
Try Hash Generator Now →DevToolKit — 42+ Free Online Developer Tools