A hash function takes any input, like a password, a file or a sentence, and turns it into a fixed-length string of characters called a hash. The same input always produces the same hash, but you can’t work backward from the hash to the input.
Quick answer: Hashes act like digital fingerprints. They’re used to verify downloads, detect changes, index data and store passwords. For security, use modern algorithms: SHA-256 for integrity checks and purpose-built password hashing like bcrypt or Argon2. MD5 and SHA-1 are no longer safe for security uses.
Key Takeaways
- Fixed-length output: Any size input, same size hash.
- Deterministic: Same input, same hash every time.
- One-way: You can’t reverse a hash.
- Tiny change, new hash: One character changes everything.
- Choose the right algorithm: Old ones are broken for security.
Common Hash Algorithms
| Algorithm | Output length | Status |
|---|---|---|
| MD5 | 128 bits | Broken for security, fine for basic checksums |
| SHA-1 | 160 bits | Deprecated for security |
| SHA-256 | 256 bits | Widely used and recommended |
| bcrypt / Argon2 | Varies | Designed for password storage |
NIST’s hash functions project page lists the approved SHA-2 and SHA-3 families and notes that SHA-1 is being phased out.
Why Hash Functions Matter
Hashes let systems compare data without storing or sending the data itself. When you log in, a well-built site compares a hash of your password with the stored hash, so the real password is never kept in plain text.
They also protect integrity. Download pages often list a SHA-256 checksum so you can confirm the file wasn’t altered. Caching systems use hashes to name files, so updated CSS or JavaScript gets a new filename.
How to Use Hash Functions
Step 1: Pick the Purpose
Decide whether you need integrity checks, indexing or password storage.
Check: You know which algorithm family fits.
Step 2: Use SHA-256 for Integrity
Hash files and compare with the published checksum.
Check: The hashes match exactly.
Step 3: Use Password Hashing Functions
Store passwords with bcrypt, Argon2 or your platform’s built-in functions, like WordPress’s password API.
Check: No passwords are stored in plain text or with plain MD5.
Step 4: Generate Quick Checksums
Use an MD5 generator for non-security tasks like detecting duplicate content.
Check: Identical inputs produce identical hashes.
Step 5: Compare Carefully
Compare full hash strings, not just the first characters.
Check: Every character matches.
An Illustrative Example
A developer downloads a plugin package from a mirror and wants to confirm it’s genuine. The official site lists a SHA-256 checksum.
They hash the downloaded zip and compare. The values match, so the file is identical to the original. If even one byte had been changed, the hash would be completely different.
Myths vs Reality
- Myth: Hashing is encryption. Reality: Encryption is reversible with a key; hashing isn’t.
- Myth: MD5 is fine for passwords. Reality: It’s fast and broken for security.
- Myth: Hashes are unique for every input. Reality: Collisions are possible, just rare with strong algorithms.
Generate an MD5 Hash
Create a quick checksum for any text.
Common Use Cases
- Password storage: Comparing hashes instead of passwords.
- Download verification: Matching published checksums.
- Cache busting: File names that change when content changes.
- Duplicate detection: Finding identical files or text.
- Version control: Git identifies commits with hashes.
Quick Tip
When comparing checksums, copy and paste the values rather than reading them by eye. Hashes are long, and two that differ by one character are completely different files. Many operating systems include built-in commands to calculate SHA-256.
Mistakes to Avoid
- Using MD5 or SHA-1 for security: Use modern algorithms.
- Unsalted password hashes: Use proper password hashing functions.
- Rolling your own crypto: Use trusted libraries.
- Comparing partial hashes: Check the full string.
- Confusing hashing with encoding: Hashes can’t be decoded.
FAQ
What Is a Hash Function?
A function that turns any input into a fixed-length, one-way fingerprint.
Can You Reverse a Hash?
No. You can only guess inputs and compare hashes.
What Is a Hash Collision?
When two different inputs produce the same hash.
What Is Salting?
Adding random data to passwords before hashing so identical passwords get different hashes.
Which Hash Should I Use?
SHA-256 for integrity and bcrypt or Argon2 for passwords.
How Does WordPress Store Passwords?
WordPress hashes passwords using its built-in password functions, never in plain text.
Is SHA-256 Secure?
Yes. It is widely used and recommended for integrity checks.
Why Not Use Fast Hashes for Passwords?
Fast hashes let attackers test billions of guesses quickly.
Where to Go Next
- Older algorithm: Read about MD5 hashes.
- Not the same: Learn about encoding.
- Unique IDs: See UUIDs.
- Hide code: Read about obfuscation.
