Encoding vs hashing explained: why anyone can reverse Base64, why a SHA-256 hash can't be undone, and which one to use when you store users' passwords.
Encoding vs hashing, explained by cats. Kitty has a note with instructions. The note must travel safely between systems. So Kitty encodes it. The note changes shape. Different symbols. Different format. Same meaning. Nothing is protected. Any kitty who understands the format can read it.
Encoding is for compatibility. For transport. And for storage. The original note can always be restored. Because encoding is reversible. Now. Hashing. Kitty takes the note and drops it into a magic mixer. The mixer always spits out a short code.
The same note always produces the same code. But the code can never turn back into the note. Hashing is one way. No undo. No reverse. Encoding changes representation. Hashing creates identity. One preserves the message. The other proves it once existed.
Encoding changes how data is written so it can be read back, while hashing turns data into a short, one-way fingerprint. Encoding and hashing serve different purposes, despite their outputs looking similarly unfamiliar.
Both can turn data into something that looks like gibberish, so they get mixed up all the time. Encoding preserves the original data; a hash cannot be decoded to recover it.
Encoding: same message, different shape
Encoding rewrites data in a different format so that another system can carry it, store it or understand it. The symbols change, but the meaning doesn't, and anyone who knows the format can turn it back.
You meet encodings everywhere:
UTF-8 turns text into bytes, so 'é' becomes two bytes a computer can store.
Percent-encoding makes text safe inside a URL, so a space becomes %20.
Base64 turns any bytes, even an image, into plain letters, digits, + and /, so they can travel through systems built only for text, such as email or JSON.
Encoding vs hashing, explained by cats. Kitty has a note with instructions. The note must travel safely between systems. So Kitty encodes it. The note changes shape. Different symbols. Different format. Same meaning. Nothing is protected. Any kitty who understands the format can read it.
Encoding is for compatibility. For transport. And for storage. The original note can always be restored. Because encoding is reversible. Now. Hashing. Kitty takes the note and drops it into a magic mixer. The mixer always spits out a short code.
The same note always produces the same code. But the code can never turn back into the note. Hashing is one way. No undo. No reverse. Encoding changes representation. Hashing creates identity. One preserves the message. The other proves it once existed.
Decoding gives back exactly the bytes you started with, every time. That round trip is what makes it encoding.
Why encoding exists
Encoding solves compatibility problems:
Transport: some channels only accept certain characters. An email body or a URL can't carry raw binary, so you encode it first.
Storage: a database column or config file may only hold text, so a small image or a key gets stored as Base64.
Interpretation: both sides need to agree on how bytes map to characters, which is what UTF-8 settles.
Encoding also has a cost. Base64 turns every 3 bytes into 4 characters, so the encoded data is about a third bigger than the original.
Encoding hides nothing
There is no key and no secret in an encoding. The format is public, so the message is only disguised from people who haven't looked it up. HTTP Basic authentication shows this well: the browser sends your username and password as Base64.
Authorization: Basic dXNlcjpwYXNz
Decode dXNlcjpwYXNz and you get user:pass. That is why Basic auth is only acceptable over HTTPS: the encryption comes from HTTPS, not from the Base64. The same goes for the middle part of a JSON Web Token, which is Base64url-encoded JSON that anyone holding the token can read.
Hashing: a fixed-size fingerprint
A hash function takes input of any size and returns a short, fixed-size value called a hash or digest. SHA-256, a common one, always returns 256 bits, written as 64 hexadecimal characters, whether you give it one word or a whole film.
Good cryptographic hash functions share a few properties:
Deterministic: the same input always gives the same hash.
One-way: given a hash, there is no practical way to work out the input.
Avalanche effect: change one character of the input and the hash changes completely.
Collision-resistant: it is practically impossible to find two different inputs with the same hash.
Change a single letter and watch what happens (only the first 16 characters are shown here):
The two inputs differ by one letter, yet the hashes share nothing you could use to tell they were close.
Why a hash can't be undone
A hash is a summary of the input, and a summary throws information away. There are endlessly many possible inputs and only a fixed number of 256-bit outputs, so the hash can't hold enough information to rebuild the original. There is no 'unhash' function.
The only way back is to guess: hash a candidate input and see whether it matches. For a long, random input that's hopeless. For a short or common input, such as a weak password, guessing can be quick, and that shapes how passwords should be stored.
What hashing is for
Because the same input always gives the same hash, a hash works as an identity for data. A securely obtained cryptographic hash lets you check a candidate copy for changes without keeping the original. A hash alone does not prove when the data existed or who created it.
Checking downloads: projects publish the SHA-256 of their release files. Obtain the expected hash from a trusted source, then hash the downloaded file. Matching cryptographic hashes provide strong evidence that it arrived intact; a hash supplied by the same attacker as a malicious file proves nothing.
Naming content: Git identifies every commit and file by a hash of its contents, so the same content always gets the same id and any change gets a new one.
Spotting duplicates: backup tools and caches compare hashes instead of comparing whole files byte by byte.
Storing passwords: a site can check your password without ever storing it.
Storing passwords with hashing
When you sign up, a well-built site hashes your password and stores only the hash. When you log in, it hashes what you typed and compares the two hashes. If they match, you typed the same password, and the site never needed to keep it.
A plain fast hash like SHA-256 is still the wrong tool here. It's built to be fast, so an attacker who steals the hashes can try billions of guesses per second, and two users with the same password get the same hash. Password hashing fixes both:
A salt: a random value, different for every user, is mixed in before hashing and stored next to the hash. Identical passwords now get different hashes, and precomputed tables of common hashes become useless.
A slow algorithm: Argon2id and scrypt deliberately use time and substantial memory per guess. Bcrypt adds an adjustable computational cost but is not memory-hard in the same way; it is mainly a legacy option. Prefer Argon2id for a new system.
Use your language's or framework's password hashing library rather than building this yourself. The OWASP Password Storage Cheat Sheet in the links below gives current settings.
Where encryption fits
Encryption is the third idea people mix into this. Like encoding, it's reversible. Unlike encoding, reversing it needs a secret key, so only the people holding the key can read the message.
Reversible?
Who can reverse it?
Encoding
Yes
Anyone who knows the format
Encryption
Yes
Only whoever holds the key
Hashing
No
Nobody
So the question to ask is what you need afterwards. If a system needs the data back in a different format, encode it. If only certain people should read it, encrypt it, and the key exchange behind HTTPS is covered in Diffie Hellman. If you only need to check or identify it later, hash it.
Common mistakes
Treating Base64 as security: encoded API keys or passwords in a config file or a URL are as exposed as plain text.
Storing passwords with a plain fast hash: unsalted MD5 or SHA-256 password hashes fall quickly to guessing once they leak. Use Argon2id, scrypt or bcrypt.
Trying to 'decrypt' a hash: sites that claim to reverse hashes are looking guesses up in huge tables of known inputs. They work only on weak or common inputs.
Hashing data you need back: if you'll need the original later, such as an email address to send messages to, hashing it means it's gone.
Using MD5 or SHA-1 where security matters: both have known collision attacks, so they are no longer safe for signatures or integrity checks against an attacker.
Key takeaways
Encoding changes how data is represented, so another system can carry, store or read it, and the original can always be restored.
Encoding hides nothing: Base64 has no key, so anyone can decode it.
Hashing turns data into a fixed-size fingerprint that can't be turned back into the data.
The same input always gives the same hash, and a one-letter change gives a completely different one.
Store passwords with a salted, slow password hash, never with encoding or a plain fast hash.