Side-by-Side Comparison

AspectHashingEncryptionEncoding
Reversible?No (one-way)Yes (with the key)Yes (no key needed)
PurposeIntegrity, verificationConfidentialityData format compatibility
Needs a key?No (may use a salt)YesNo
Output sizeFixed lengthVaries with inputVaries with input
ExampleSHA-256, bcryptAES, RSABase64, URL encoding
Typical usePassword storage, checksums, digital signaturesProtecting data in transit/at restEmbedding binary data in text (emails, URLs, JSON)

Hashing: One-Way, Fixed-Size, Irreversible

conceptual example hash("password123") -> "ef92b778bafe771e89245b89ecbc08a" hash("password124") -> "8d969eef6ecad3c29a3a629280e686c" (completely different output)

A tiny change to the input produces a completely different output (the "avalanche effect"), and there is no operation that takes the hash output and recovers "password123". This is exactly why hashing fits password storage: the server only ever needs to check "does hashing this login attempt match the stored hash?" — it never needs to know the real password.

⚠️ Don't Use Fast Hashes for Passwords

SHA-256 and MD5 are built to be fast — great for checksums, terrible for passwords, because attackers can brute-force billions of guesses per second on a GPU. Use bcrypt, scrypt, or Argon2 instead — they are deliberately slow and tunable, making brute-forcing computationally expensive even at scale.

Encryption: Two-Way, Needs a Key

Encryption transforms data so it's unreadable without the correct key, but it's designed to be reversed by whoever holds that key:

conceptual example encrypt("Meet at 5pm", key) -> "U2FsdGVkX1+8mF3K9..." decrypt("U2FsdGVkX1+8mF3K9...", key) -> "Meet at 5pm"

This is used whenever the original data needs to be recovered later — encrypting a database column, securing data in transit over HTTPS, or protecting files at rest. Symmetric encryption (AES) uses one shared key for both directions; asymmetric encryption (RSA) uses a public/private key pair.

Encoding: Just a Different Format, No Security

conceptual example encode("Hello", "base64") -> "SGVsbG8=" decode("SGVsbG8=", "base64") -> "Hello"

Base64 encoding exists to safely represent binary data as plain text — for example, embedding an image inside a JSON payload or a URL. It provides zero confidentiality: anyone can decode it instantly with a standard library, no key required. Encoding answers "how do I represent this data safely in a different format?" — not "how do I keep this secret?"

The Classic Mistake: Encrypting Passwords

If passwords are encrypted rather than hashed, anyone who steals the encryption key (a misconfigured server, a leaked environment variable, an insider) can decrypt and read every user's actual password in plaintext. If passwords are properly hashed with a strong algorithm and a unique salt per user, a database breach alone does not hand attackers usable passwords — they'd need to crack each hash individually, which a slow algorithm like bcrypt makes expensive.

Hashing in Data Structures (a Different Use)

Hash functions also power hash tables (dictionaries/maps), where speed and even key distribution matter far more than cryptographic security. A hash table's hash function converts a key into an array index for near O(1) lookups — collisions are handled with chaining or open addressing, not treated as a security failure the way they would be for a cryptographic hash.

💡 Quick Mental Test

Ask: "Do I ever need to get the original value back?" If no — hash it. If yes, and it must stay secret — encrypt it. If yes, and secrecy doesn't matter, just needs a safe format — encode it.

How We Research and Update This Guide

We test the underlying formula or workflow, compare outputs with reliable references, and revise examples whenever the page content changes.

  • The workflow or formula is tested directly in the tool and compared against independent reference examples.
  • Examples are kept practical so readers can verify the result without hidden assumptions.
  • Pages are revised whenever the interface, calculation flow, or surrounding guidance materially changes.

Frequently Asked Questions — Hashing vs Encryption vs Encoding