Hashing vs Encoding vs Encryption: What Is the Difference?
7 min read · Published 1 November 2026 · Updated 2 November 2026
Encoding, hashing and encryption are often mixed up, and the mix-up leads to real vulnerabilities, such as "encrypting" passwords with Base64 or storing them with a fast hash. They solve different problems. This guide gives you a simple way to tell them apart and to choose the right one.
In this guide
Encoding: changing the format
Encoding transforms data into another representation so that it can be stored or transmitted correctly. It is public, reversible and uses no secret. Examples are Base64, URL percent-encoding, UTF-8 and HTML entities. Encoding provides no security at all. Its goal is compatibility.
Encryption: keeping data secret
Encryption scrambles data using a key so that only someone with the right key can read it. It is reversible, but only with the key. Symmetric encryption, such as AES, uses the same key to encrypt and decrypt. Asymmetric encryption, such as RSA and elliptic-curve schemes, uses a public key to encrypt and a private key to decrypt. Use authenticated modes such as AES-GCM or ChaCha20-Poly1305, which also detect tampering, rather than older modes that only hide data.
Hashing: a fingerprint
A hash function turns any input into a fixed-size value (the digest). It is designed to be one way: you cannot work backwards from the digest to the input. The same input always gives the same digest, and a tiny change to the input changes the digest completely. For example, the SHA-256 hash of the text "hello" is:
SHA-256 of "hello"
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824What hashes are used for
Not every hash function is still safe. MD5 and SHA-1 have known collision attacks, so they should not be used for security purposes. SHA-256 and the other members of the SHA-2 and SHA-3 families are the common choices today.
- Integrity: compare the hash of a downloaded file with the published hash to check it was not altered.
- Identification: content-addressed storage and caches use hashes as keys.
- Passwords, but only with special slow hash functions (see below).
HMAC and signatures: proving who made it
A plain hash can be recomputed by anyone, so it cannot prove who created the data. An HMAC combines a hash function with a secret key, so only someone who knows the key can produce or check the value. This is how the HS256 signature in a JSON Web Token works. A digital signature (RSA, ECDSA, Ed25519) does the same job with a key pair: it is created with a private key and checked with a public key, so anyone can verify it and only the owner can produce it.
Passwords need special treatment
Fast hashes such as SHA-256 let an attacker who steals your database test billions of guesses per second. Passwords should be stored with a purpose-built, deliberately slow and memory-hungry function such as Argon2id, scrypt or bcrypt, together with a unique random salt for each password. The salt makes identical passwords produce different hashes and defeats precomputed tables. You never need to be able to recover a password, so you never decrypt it: you hash the attempt and compare.
At a glance
- Encoding: reversible, no key, goal is format compatibility (Base64, URL encoding).
- Encryption: reversible with a key, goal is confidentiality (AES-GCM, RSA).
- Hashing: one way, no key, goal is a fingerprint or integrity check (SHA-256).
- Password hashing: one way, slow and salted, goal is safe password storage (Argon2id, bcrypt).
- HMAC and signatures: need a key, goal is authenticity and integrity (HS256, Ed25519).
Common mistakes
- Treating Base64 as encryption.
- Storing passwords with MD5, SHA-1 or a single round of SHA-256.
- Inventing your own encryption scheme instead of using a proven library.
- Reusing a nonce or IV with the same key in a mode that forbids it.
- Encrypting data but never checking that it was not modified, which is why authenticated modes are preferred.
Frequently asked questions
- Can a hash be reversed?
- Not directly. But a short or common input can be found by guessing: an attacker hashes many candidate inputs and looks for a match. That is why passwords need slow hashes and salts, and why strong, long passwords matter.
- Is SHA-256 encryption?
- No. It is a hash function. It produces a fixed-size fingerprint and cannot be decrypted, because there is nothing to decrypt.
- What is a salt?
- A random value stored alongside each password hash and mixed into it. It ensures that two users with the same password get different hashes.
- Which should I use to check a downloaded file?
- Compare a SHA-256 hash of the file with the one published by the source over a trusted channel. A digital signature gives stronger assurance of who published it.
Sources and further reading
Try it yourself: JWT Encoder & Decoder runs in your browser, free and with no sign-up.