Hashing turns data into a fixed-length fingerprint that can't be turned back, while encryption scrambles data so that someone with the right key can turn it back. Use hashing when you only need to check that something matches, like a password or a download. Use encryption when you need the original data again later, like a message or a backup.
Mixing the two up causes real security mistakes, such as storing passwords with reversible encryption or treating an encoded token as private.
The difference at a glance
| Hashing | Encryption | |
|---|---|---|
| Can you get the original back? | No | Yes, with the key |
| Uses a key? | No (HMAC adds one) | Yes |
| Output size | Fixed, whatever the input | Grows with the input |
| Answers the question | "Is this the same data?" | "Who can read this data?" |
| Typical uses | Passwords, checksums, signatures | Messages, files, disks, connections |
| Common algorithms | SHA-256, Argon2id, bcrypt | AES-256, ChaCha20, RSA |
How hashing works
A hash function reads any amount of data and outputs a short value of fixed length. SHA-256 always produces 64 hexadecimal characters, whether you feed it one word or a whole film.
Three properties make it useful:
- Same input, same output. Hash a file today and next year, and you get the same value.
- Tiny change, totally different output. Change one letter and the hash looks unrelated to the old one.
- One way. There's no key and no method to rebuild the input from the hash. The only way back is to guess inputs and hash each guess until one matches.
That's why hashes are good for checking. A download page lists a file's hash, and you compare it with yours, as described in how to verify a file checksum.
How encryption works
Encryption takes data and a key and produces ciphertext that looks like random noise. With the right key, the process runs backwards and returns the exact original. Without it, the ciphertext is useless.
There are two kinds:
1. Symmetric encryption
One key encrypts and decrypts. AES-256 is the standard choice, used for disk encryption, encrypted files and the bulk of every HTTPS connection. It's fast, but both sides need the same key, so you have to share that key safely.
2. Asymmetric encryption
A key pair: a public key that anyone can use to encrypt, and a private key that only the owner uses to decrypt. It solves the key-sharing problem, so it's used to set up secure connections and to sign data. It's much slower, so systems usually use it to agree on a symmetric key and then switch to symmetric encryption for the data itself.
Which one protects passwords?
Hashing, always. A service never needs to know your password, only to check that what you type matches what you set. Storing a hash lets it do exactly that.
Encryption is the wrong tool here. If passwords are encrypted, the key sits somewhere on the same systems, and one breach that exposes the key exposes every password at once.
A plain fast hash like SHA-256 isn't enough either. Attackers who steal a database of fast hashes can test billions of guesses per second. Password storage needs a deliberately slow hash with a unique random salt per password. The OWASP password storage cheat sheet recommends Argon2id first, then scrypt, bcrypt for older systems, and PBKDF2 where FIPS compliance requires it. Modern libraries for these handle the salt for you.
What about encoding?
Encoding, such as Base64, is a third thing that often gets confused with both. It changes data into another format so it survives being sent as text, and anyone can reverse it without a key. It hides nothing. A JWT's payload, for example, is only encoded, which is why anyone holding a JWT can read it.
Where you meet both together
Real systems usually combine them:
- HTTPS encrypts the connection and uses hashes inside its certificates and integrity checks.
- Password managers encrypt your vault with a key derived from your master password through a slow hash.
- HMAC mixes a secret key into a hash, so the result proves both that the data is unchanged and that it came from someone with the key. Webhooks and many API tokens are signed this way; the HMAC generator shows how.
- Encrypting a note with a password works the same way: a slow hash turns the password into an encryption key, and the key encrypts the text.
Frequently asked questions
Can a hash be decrypted?
No, because nothing was encrypted. Sites that claim to "decrypt" hashes look the hash up in huge tables of hashes of common passwords and words. That works only for inputs someone has already guessed, which is why unique, long passwords and salted slow hashes defeat it.
Is MD5 or SHA-1 still safe?
Not for security. Researchers can produce two different inputs with the same MD5 or SHA-1 hash, so they can't prove a file wasn't swapped. Both still catch accidental corruption. For anything security related, use SHA-256 or stronger, and a dedicated password hash for passwords.
Is encryption always better than hashing?
They solve different problems. Encryption keeps data private while letting key holders read it. Hashing proves data is unchanged or matches, without keeping the data at all. Choosing the wrong one, such as encrypting passwords, makes a system weaker rather than stronger.
Is Base64 a form of encryption?
No. Base64 is encoding: a reversible format change with no key. Anyone can decode it in a second, so it offers no secrecy. It's used to carry binary data, like images or keys, inside text formats such as email, JSON and URLs.
Try both in your browser
Create SHA-256 and other hashes of any text with the hash generator, and lock a note with a password using the encrypt text tool, which uses AES-256 with a key derived from your password. Both run entirely on your device.