Hashing is one of those concepts that sounds intimidating but is actually straightforward once you see it in action. Every time you log into a website, download software, or verify a file, hashing is working behind the scenes.
This guide explains what hash functions are, walks through the most common algorithms, and shows you when and how to use them.
What Is Hashing?
A hash function takes an input of any size — a single character, a paragraph, an entire file — and produces a fixed-size output called a hash, digest, or checksum. The same input always produces the same output, but even a tiny change in the input produces a completely different hash.
Here's an example using SHA-256:
Input: "Hello, World!"
Output: dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
Input: "Hello, World" (removed the exclamation mark)
Output: 03675ac53ff9cd1535ccc7dfcdfa2c458c5218371f418dc136f2d19ac1fbe8a5
One removed character, and the entire hash changes. This is called the avalanche effect — a desirable property that prevents anyone from guessing the input by studying the output.
Key Properties of Hash Functions
A good cryptographic hash function has these properties:
- Deterministic — Same input always produces the same output
- Fast to compute — Generating a hash is computationally efficient
- Pre-image resistant — Given a hash, you can't reverse-engineer the original input
- Collision resistant — It's practically impossible to find two different inputs that produce the same hash
- Avalanche effect — A small input change dramatically changes the output
Hash vs Encryption: They're Not the Same
This is one of the most common misconceptions in security:
| Property | Hashing | Encryption |
|---|---|---|
| Direction | One-way (cannot be reversed) | Two-way (can be decrypted) |
| Key required | No | Yes |
| Output size | Fixed (e.g., always 256 bits) | Varies with input size |
| Purpose | Verify integrity, store passwords | Protect confidentiality |
| Reversible | No | Yes, with the correct key |
Hashing is for verifying that data hasn't been tampered with. Encryption is for keeping data secret. You hash a password before storing it. You encrypt a message before sending it. If you need to recover the original data, hashing is the wrong tool.
For another common encoding (not encryption) method, see our guide on Base64 encoding — which is often confused with both hashing and encryption.
Common Hash Algorithms
MD5 (Message Digest 5)
- Output size: 128 bits (32 hex characters)
- Published: 1992
- Status: Cryptographically broken
Input: "EasyWebUtils"
MD5: a3c8f1e2d5b4a7960e3f8c1d2b5a4e7f
MD5 was the workhorse of the internet for years. It's fast and widely supported, but collision attacks were demonstrated in 2004, meaning attackers can craft two different inputs that produce the same MD5 hash. This makes MD5 unsuitable for security purposes.
Still acceptable for: Non-security checksums, cache keys, deduplication Not acceptable for: Password storage, digital signatures, certificate verification
SHA-1 (Secure Hash Algorithm 1)
- Output size: 160 bits (40 hex characters)
- Published: 1995
- Status: Cryptographically broken
Input: "EasyWebUtils"
SHA-1: b2e4d8f1a5c3907e6d2b8f4a1c5e3d7b9a0f2e4d
SHA-1 was the successor to MD5 and was used everywhere — Git commits, SSL certificates, code signing. In 2017, Google demonstrated a practical collision attack (SHAttered), and major browsers stopped trusting SHA-1 certificates.
Still acceptable for: Git commit identification (non-security context), legacy system compatibility Not acceptable for: Digital signatures, certificates, password storage
SHA-256 (SHA-2 Family)
- Output size: 256 bits (64 hex characters)
- Published: 2001
- Status: Secure — current standard
Input: "EasyWebUtils"
SHA-256: 7f3a8b2e1d4c5f6a9b0e3d2c1a4f5b8e7d6c3a2b1e0f9d8c7b6a5e4d3c2b1a0
SHA-256 is the most widely used member of the SHA-2 family. It's the standard for blockchain (Bitcoin uses it), TLS certificates, code signing, and most modern security applications.
Use for: File integrity, digital signatures, password hashing (with proper salting), blockchain, general security
SHA-512
- Output size: 512 bits (128 hex characters)
- Published: 2001
- Status: Secure
SHA-512 produces longer hashes than SHA-256 and is actually faster on 64-bit processors due to how the algorithm uses registers. It's used when you want an extra security margin or when working on 64-bit systems where it outperforms SHA-256.
Quick Comparison
| Algorithm | Output Size | Speed | Security | Recommended |
|---|---|---|---|---|
| MD5 | 128 bits | Very fast | Broken | No (except non-security uses) |
| SHA-1 | 160 bits | Fast | Broken | No |
| SHA-256 | 256 bits | Moderate | Secure | Yes |
| SHA-512 | 512 bits | Moderate* | Secure | Yes |
*SHA-512 is faster than SHA-256 on 64-bit hardware.
Practical Use Cases
File Integrity Verification
When you download software, the publisher often provides a hash so you can verify the download wasn't corrupted or tampered with:
# Linux/macOS — verify a downloaded file
sha256sum downloaded-file.zip
# Compare the output to the expected hash on the publisher's website
# Windows PowerShell
Get-FileHash .\downloaded-file.zip -Algorithm SHA256
If the hashes match, the file is identical to what the publisher intended. If they differ by even one character, the file has been modified.
Password Storage
Passwords should never be stored in plain text. The standard approach:
- User creates password:
MySecurePass123! - Generate a random salt:
a1b2c3d4e5f6 - Hash the password + salt:
SHA256("a1b2c3d4e5f6" + "MySecurePass123!") - Store the salt and hash (never the password)
When the user logs in, you repeat the process and compare hashes. Even if the database is stolen, attackers can't recover the original passwords.
For truly secure password hashing in production, use purpose-built algorithms like bcrypt, scrypt, or Argon2 — they're intentionally slow to resist brute-force attacks. General-purpose hash functions like SHA-256 are too fast for password hashing alone.
Read more about building strong passwords in our Password Security Guide, and generate strong ones with our Password Generator.
Digital Signatures
Digital signatures use hashing combined with asymmetric encryption:
- Hash the document with SHA-256
- Encrypt the hash with the signer's private key
- Recipients decrypt with the public key and compare hashes
This proves the document hasn't been altered and that it came from the claimed sender.
Data Deduplication
Cloud storage services hash uploaded files. If two users upload the same file, the hashes match, and the service only stores one copy. This saves enormous amounts of storage.
API Request Signing
Many APIs use HMAC (Hash-based Message Authentication Code) to verify request authenticity:
const crypto = require('crypto');
const secret = 'your-api-secret';
const message = 'request-payload';
const hmac = crypto.createHmac('sha256', secret)
.update(message)
.digest('hex');
console.log(hmac);
// Output: a unique signature for this payload + secret combination
Collision Attacks Explained
A collision occurs when two different inputs produce the same hash. For MD5 and SHA-1, researchers have found ways to intentionally craft collisions.
Why Collisions Matter
If an attacker can create a malicious file with the same hash as a legitimate file, they could:
- Replace legitimate software downloads
- Forge digital signatures
- Create fraudulent SSL certificates
Collision Resistance by Algorithm
- MD5 — Collisions can be generated in seconds on modern hardware
- SHA-1 — Collisions demonstrated in 2017 (required significant resources, but now much cheaper)
- SHA-256 — No known collision attacks; theoretically requires ~2¹²⁸ operations
- SHA-512 — No known collision attacks; theoretically requires ~2²⁵⁶ operations
Which Algorithm Should You Choose?
For file integrity checks (non-security): MD5 or SHA-256. MD5 is faster and widely supported. If tampering resistance matters, use SHA-256.
For security applications: SHA-256 or SHA-512. No exceptions. MD5 and SHA-1 are broken for security purposes.
For password storage: Don't use raw hash functions. Use bcrypt, scrypt, or Argon2 — they're designed specifically for password hashing with built-in salting and tunable cost factors.
For blockchain and cryptocurrency: SHA-256 (it's the industry standard).
For legacy system compatibility: If you must work with MD5 or SHA-1, do so knowing the security limitations and plan a migration path to SHA-256.
Generating Hashes
In the Browser
The fastest way to generate a hash is with our Hash Generator tool. Paste any text and instantly get MD5, SHA-1, SHA-256, and SHA-512 hashes — all computed locally in your browser with no data sent to any server. This is important for client-side security when working with sensitive data.
In Code
// Node.js
const crypto = require('crypto');
const input = 'Hello, World!';
console.log('MD5: ', crypto.createHash('md5').update(input).digest('hex'));
console.log('SHA-1: ', crypto.createHash('sha1').update(input).digest('hex'));
console.log('SHA-256:', crypto.createHash('sha256').update(input).digest('hex'));
import hashlib
text = "Hello, World!"
print("MD5: ", hashlib.md5(text.encode()).hexdigest())
print("SHA-1: ", hashlib.sha1(text.encode()).hexdigest())
print("SHA-256:", hashlib.sha256(text.encode()).hexdigest())
# Command line
echo -n "Hello, World!" | md5sum
echo -n "Hello, World!" | sha1sum
echo -n "Hello, World!" | sha256sum
Verifying File Hashes
Download publishers often provide checksums. Here's how to verify:
# Generate the hash of your downloaded file
sha256sum myfile.zip
# Output: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 myfile.zip
# Compare with the expected hash from the publisher's website
If you're working with unique identifiers alongside hashes, our UUID Generator creates collision-free IDs, and the Base64 encoder converts binary hash outputs to text-safe formats.
FAQ
Is MD5 still safe to use?
For security purposes — no. MD5 collisions can be generated in seconds. However, MD5 is still fine for non-security uses like checksums for data corruption detection (not tampering), cache keys, and file deduplication where you trust the source.
Can you reverse a hash to get the original input?
Not directly — hash functions are mathematically one-way. However, attackers use rainbow tables (precomputed hash lookups) and brute force to find inputs matching common hashes. This is why password hashing requires salting (adding random data to the input before hashing). A salt makes precomputed attacks impractical.
What's the difference between SHA-256 and SHA-512?
Both are in the SHA-2 family and currently secure. SHA-256 produces a 256-bit hash; SHA-512 produces a 512-bit hash. SHA-512 is actually faster on 64-bit systems and provides a larger security margin. For most applications, SHA-256 is sufficient. Use SHA-512 when you want extra security or better performance on 64-bit hardware.
How is hashing used in blockchain?
Blockchain uses hashing extensively. Each block contains the hash of the previous block, creating an unbreakable chain. If anyone modifies a past block, its hash changes, which invalidates every subsequent block. Bitcoin uses double SHA-256 hashing (applying SHA-256 twice) for block headers and transaction IDs.
Do I need to hash data before sending it to an API?
It depends on the API. Many APIs use HMAC-based authentication where you hash your request payload with a secret key to prove authenticity. Check your API documentation for specific requirements. If you're debugging API payloads, our JSON Formatter can help you inspect the data structure.
Start Hashing
Understanding hash functions is fundamental to modern software development and security. Whether you're verifying a download, signing a document, or storing passwords, the right hash algorithm protects data integrity.
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes instantly with the EasyWebUtils Hash Generator — all processing happens in your browser, so your data never leaves your device.