Hashing turns data into a fixed-length fingerprint that cannot be turned back into the original, and it uses no key; encryption scrambles data with a key so that anyone holding the right key can turn it back. Use hashing to check that data hasn't changed or to verify passwords without storing them, and encryption when you need to read the data again later.
Hashing vs encryption at a glance
| Hashing | Encryption | |
|---|---|---|
| Reversible? | No, one-way | Yes, with the key |
| Key needed? | No (HMAC adds one) | Yes |
| Output size | Fixed, whatever the input (SHA-256: 256 bits, 64 hex characters) | About the same size as the input, plus a little overhead |
| Same input, same output? | Always (unless a salt is added) | No, with a random IV or nonce each time |
| Used for | File checksums, password storage, signatures, deduplication | HTTPS, disk encryption, encrypted files and messages |
| Examples | SHA-256, SHA-3, Argon2id, bcrypt | AES, ChaCha20, RSA |
What hashing does
A hash function takes any amount of data and produces a short, fixed-length value called a digest. NIST's Secure Hash Standard (FIPS 180-4) describes the purpose plainly: digests are used to detect whether messages have changed since the digest was generated.
You can check this yourself. The SHA-256 hash of the three letters abc is a published test value, and any correct implementation produces it:
printf 'abc' | sha256sum
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad -
printf 'abd' | sha256sum
a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9 -
Changing one letter changes the whole output, with no visible relationship between the two. And there is no key and no "unhash" command. The 64-character digest has a fixed size whether the input is 3 bytes or 3 GB, so it cannot contain the original data. The only way back is to guess inputs and compare their hashes.
On Windows, PowerShell gives the same result for a file with Get-FileHash .\file.zip -Algorithm SHA256. To hash text or files in the browser without uploading them, use the hash generator or the file checksum calculator.
What encryption does
Encryption transforms data using a key, and the right key reverses it. AES, the standard defined in NIST FIPS 197, is a block cipher that works on 128-bit blocks with keys of 128, 192 or 256 bits (AES-128, AES-192 and AES-256). It is symmetric: the same key encrypts and decrypts.
A round trip with OpenSSL 3.2, deriving the key from a passphrase with PBKDF2:
printf 'hello' > m.txt
openssl enc -aes-256-cbc -pbkdf2 -iter 600000 -salt -in m.txt -out m.enc -pass pass:example-passphrase
openssl enc -d -aes-256-cbc -pbkdf2 -iter 600000 -in m.enc -pass pass:example-passphrase
hello
With the wrong passphrase, decryption fails rather than producing the text:
bad decrypt
Run the encryption twice and you get different ciphertext each time, because a random salt is mixed in. That is deliberate: identical messages shouldn't produce identical ciphertext.
Asymmetric encryption, such as RSA, uses a pair of keys instead: a public key to encrypt and a private key to decrypt. See public-key cryptography explained for how that works. To encrypt text in the browser with AES-256-GCM, try the text encryption tool.
Why passwords are hashed, not encrypted
A login system never needs to know your password, only whether what you typed matches. So it stores a hash, hashes each login attempt the same way, and compares. If the database leaks, there is no key that unlocks all the passwords at once. Encrypted passwords would be one stolen key away from a full leak. OWASP's Password Storage Cheat Sheet puts it this way: hashing is a one-way function and encryption is a two-way function, and passwords should be hashed.
But not with a plain, fast hash. SHA-256 is built for speed, which lets an attacker test enormous numbers of guesses against a leaked hash. Password storage uses two extra defences:
- A salt: a unique random value added to each password before hashing. Two users with the same password get different hashes, and precomputed tables of hashes are useless.
- A deliberately slow algorithm. OWASP's current recommendations (as of October 2026): Argon2id with at least 19 MiB of memory, 2 iterations and 1 degree of parallelism; scrypt if Argon2id isn't available; bcrypt with a work factor of 10 or more for legacy systems; and PBKDF2-HMAC-SHA256 with 600,000 iterations where FIPS-140 compliance is required.
How much the slowness helps depends on the password itself; see how long it takes to crack a password and password entropy explained.
When to use which
| Task | Use |
|---|---|
| Check a download wasn't corrupted or tampered with | Hash (compare with the publisher's SHA-256) |
| Store user passwords | Salted slow hash (Argon2id, scrypt, bcrypt, PBKDF2) |
| Prove an API request or webhook came from someone with a shared secret | HMAC (a keyed hash) |
| Store a document, backup or database field you must read later | Encryption (AES-GCM or ChaCha20-Poly1305) |
| Send data over a network privately | Encryption (TLS does this for HTTPS) |
| Find duplicate files | Hash |
For the HMAC case, the HMAC generator computes and verifies HMAC-SHA256 values in the browser.
Common mix-ups
- "Decrypting" a hash. Websites that claim to reverse MD5 or SHA hashes are looking the hash up in a database of hashes of common inputs. It works for weak passwords and fails for anything long and random.
- Calling Base64 encryption. Base64 is an encoding with no key; anyone can decode it.
- Using MD5 or SHA-1 for security. Both are still fine for spotting accidental corruption, but collisions (two different inputs with the same hash) can be produced deliberately for both: RFC 6151 says MD5 is no longer acceptable where collision resistance is required, and NIST is phasing SHA-1 out by the end of 2030. Don't rely on either where an attacker is involved. Use SHA-256 or newer.
- Encrypting without authentication. Plain AES-CBC hides data but doesn't detect tampering. Authenticated encryption modes such as AES-GCM (NIST SP 800-38D) also detect changes to the ciphertext, which is why they are the usual choice for new code.
Frequently asked questions
- Can a hash be decrypted?
- No. A hash has no key and throws information away, so there is nothing to decrypt. What attackers do instead is guess: they hash candidate inputs and compare the results. That works against short or common inputs such as weak passwords, which is why password hashes use salts and deliberately slow algorithms.
- Is Base64 encryption?
- No. Base64 is an encoding: it changes how bytes are written so they survive text-only channels, and anyone can reverse it without a key. It provides no secrecy at all.
- Is SHA-256 good for storing passwords?
- Not on its own. SHA-256 is designed to be fast, which lets an attacker test billions of guesses. OWASP recommends a slow, salted password hashing algorithm instead: Argon2id first, then scrypt, bcrypt for legacy systems, or PBKDF2 with a high iteration count where FIPS-140 compliance is required.
- What is the difference between hashing and HMAC?
- A plain hash proves data hasn't changed only if you get the hash from a trusted place, because anyone can compute a new hash for altered data. HMAC mixes a secret key into the hash, so only someone holding the key can produce a valid tag. It is used to authenticate API requests and webhooks.
- Is encryption more secure than hashing?
- Neither is more secure in general; they solve different problems. Encryption protects data you need to read again. Hashing proves integrity or lets you check a secret without storing it. Using the wrong one, such as encrypting passwords, is the actual security mistake.