Encoding, hashing and encryption all transform data into something that looks like gibberish. That is where the similarity ends. They have completely different purposes, and confusing them is behind some of the most common security mistakes in software: passwords “protected” with Base64, files “encrypted” with a hash, or secrets hidden in tokens anyone can read.
This guide explains each in plain English, with examples, and gives you a simple rule of thumb for which one you need.
The one-sentence version
- Encoding changes the format of data so a system can carry it. Anyone can reverse it. It provides no secrecy.
- Hashing creates a fixed-size fingerprint of data. It can’t be reversed. It is used to check integrity and to store passwords safely.
- Encryption scrambles data so only someone with the right key can read it. It is used for confidentiality.
| Encoding | Hashing | Encryption | |
|---|---|---|---|
| Purpose | Compatibility | Integrity, fingerprinting | Confidentiality |
| Reversible? | Yes, by anyone | No | Yes, with the key |
| Uses a key? | No | No (HMAC adds one) | Yes |
| Output size | Depends on input | Fixed | Depends on input |
| Examples | Base64, URL encoding, UTF-8 | SHA-256, SHA-512, bcrypt, Argon2 | AES, ChaCha20, RSA, TLS |
Encoding: making data fit
Encoding is about representation. Systems have rules about which characters they accept, and encoding transforms data to follow those rules.
Character encoding and UTF-8
Computers store text as numbers. A character encoding maps characters to bytes. UTF-8 is the dominant encoding on the web: it can represent every character in Unicode — Latin, Arabic, Devanagari, Chinese, emoji — and is backwards-compatible with ASCII. When text shows up as garbled symbols, the usual cause is text saved in one encoding being read as another.
Base64
Base64 represents binary data (images, files, encrypted bytes) using 64 printable characters: A–Z, a–z, 0–9, + and /, with = for padding. It exists because many systems — email, JSON, HTML attributes — are designed for text, not raw bytes.
- Every 3 bytes become 4 characters, so Base64 is about a third larger than the original.
- Base64url swaps
+and/for-and_so the result is safe in URLs and file names. JSON Web Tokens use it. - Data URIs such as
data:image/png;base64,...embed small files directly in HTML or CSS.
Try it with our Base64 encoder and decoder. You’ll see that decoding needs no key or password at all.
URL encoding
URLs can only contain a limited set of characters, and some characters (?, &, =, #, /) have special meanings. Percent-encoding replaces other characters with % followed by hexadecimal byte values: a space becomes %20, and “é” in UTF-8 becomes %C3%A9.
The classic bug is building a URL with a value that contains & or # without encoding it, which silently breaks the query string. Our URL encoder shows both the component and whole-URL forms.
The key point
Hashing: one-way fingerprints
A hash function takes input of any size and produces a fixed-size output, the hash or digest. Good cryptographic hash functions have three properties:
- Deterministic: the same input always gives the same hash.
- One-way: you can’t work backwards from the hash to the input.
- Collision-resistant: it is infeasible to find two different inputs with the same hash.
A tiny change in the input changes the output completely. The SHA-256 hash of “hello” looks nothing like the hash of “Hello”.
You can calculate SHA-1, SHA-256, SHA-384 and SHA-512 hashes of text or files with our hash generator, which uses your browser’s built-in Web Crypto API.
What hashing is used for
- File integrity. Software downloads often publish a SHA-256 checksum. If your file’s hash matches, it hasn’t been corrupted or altered.
- Deduplication and caching. Identical content gives identical hashes, so systems can spot duplicates or cache files by content.
- Version control. Git identifies commits and files by hashes of their content.
- Digital signatures. Documents are hashed, then the hash is signed.
Retired algorithms
MD5 and SHA-1 are broken for security purposes: practical collisions have been demonstrated. They still appear in legacy checksums and non-security uses, but use SHA-256 or stronger for anything security-related.
HMAC: hashing with a key
A plain hash proves data hasn’t changed only if the hash itself is trustworthy. An attacker who changes a message can simply recalculate its hash. HMAC (hash-based message authentication code) mixes a secret key into the hashing process, so only someone with the key can produce a valid code.
HMAC is used to sign API requests, verify webhooks from payment providers and sign JWTs with HS256. The hash generator calculates HMACs when you enter a key, and our JWT decoder uses HMAC to verify HS256 tokens.
Passwords need special hashing
Websites shouldn’t store passwords at all — they should store a hash, so a database leak doesn’t reveal them. But fast hashes like SHA-256 are the wrong tool. They are designed to be quick, so attackers with ordinary graphics cards can try vast numbers of guesses per second against a leaked hash.
Password hashing needs algorithms that are deliberately slow and memory-hungry:
- Argon2id — the winner of the Password Hashing Competition and a common recommendation for new systems.
- scrypt and bcrypt — long-established, widely supported options.
- PBKDF2 — widely available and accepted in some compliance regimes, best with a high iteration count.
Each password also needs a unique random salt, stored with the hash, so identical passwords produce different hashes and precomputed lookup tables (rainbow tables) are useless. Modern password-hashing libraries handle salts for you.
Users can help by choosing long, unique passwords for every site — our password generator creates them with your browser’s cryptographic random number generator — and using a password manager.
Encryption: keeping secrets
Encryption turns readable data (plaintext) into unreadable data (ciphertext) using a key. Only someone with the right key can decrypt it. It is the only one of the three that provides confidentiality.
Symmetric encryption
Symmetric encryption uses one key to encrypt and decrypt. It is fast and used for most bulk data.
- AES is the most widely used symmetric cipher, often in the GCM mode, which also detects tampering.
- ChaCha20-Poly1305 is a modern alternative that performs well on devices without AES hardware support.
The hard part is key management: both sides need the key, and it must be kept secret.
Asymmetric encryption
Asymmetric (public-key) encryption uses a key pair: a public key that can be shared with anyone and a private key that must be kept secret. Data encrypted with the public key can only be decrypted with the private key.
- RSA and elliptic-curve schemes are the common families.
- Asymmetric operations are much slower than symmetric ones, so they are typically used to exchange or protect a symmetric key, which then encrypts the actual data.
- Key pairs also enable digital signatures: signing with the private key, verifying with the public key.
TLS: encryption you use every day
When you visit a site over HTTPS, your browser and the server use TLS. At a high level:
- The server presents a certificate proving it controls the domain, signed by a certificate authority your browser trusts.
- Browser and server use asymmetric cryptography to agree on fresh symmetric keys.
- All traffic is then encrypted with fast symmetric encryption, with integrity checks.
TLS protects data in transit. Data at rest — databases, backups, laptops, phones — needs its own encryption, typically handled by the database, storage service or operating system.
End-to-end encryption
In end-to-end encryption, only the communicating users hold the keys; the service in the middle can’t read the content. Messaging apps use this. It is different from TLS, where the server decrypts traffic it receives.
Choosing the right one
Ask what you are trying to achieve:
- “This system can’t handle these characters or bytes.” → Encoding.
- “I need to check this data hasn’t changed.” → Hashing (or HMAC if attackers could change the hash too).
- “I need to verify a password without storing it.” → Password hashing: Argon2id, scrypt, bcrypt or PBKDF2, with salts.
- “Only authorised people should be able to read this.” → Encryption.
- “I need to prove who sent this.” → Digital signatures or HMAC.
Common mistakes
- Base64 “encryption”. Storing API keys or passwords in Base64 is the same as storing them in plain text.
- Fast hashes for passwords. SHA-256 or MD5 of a password, with or without a salt, is too fast to resist offline cracking.
- Rolling your own crypto. Use well-reviewed libraries and standard algorithms; small implementation mistakes break security completely.
- Hard-coded keys. Encryption keys committed to source code or shipped in apps can be extracted. Keep secrets in a secrets manager or environment configuration.
- Ignoring key rotation. Plan how to replace keys if they leak, and how to re-encrypt data.
- Secrets in JWT payloads. Signed tokens are readable; see our JWT guide.
Security basics like these are covered in our website security checklist. If you need a second pair of eyes on how your application handles passwords, keys or sensitive data, KRA Digital offers web security reviews and secure development. More definitions are in our web development glossary.
Frequently asked questions
Is Base64 encryption?
No. Base64 is an encoding that represents binary data as text. Anyone can decode it without a key, so it provides no secrecy at all.
Can a hash be reversed?
A cryptographic hash can’t be mathematically reversed. Attackers can, however, guess inputs and compare hashes, which is why short or common inputs such as weak passwords are vulnerable and why passwords need slow, salted hashing algorithms.
What is the difference between hashing and encryption?
Hashing is one-way: it produces a fingerprint that can’t be turned back into the original. Encryption is two-way: data can be decrypted with the right key. Use hashing to verify, encryption to keep secret.
Which algorithm should I use to store passwords?
Use a dedicated password-hashing algorithm such as Argon2id, scrypt, bcrypt or PBKDF2 with a unique salt per password, through a well-maintained library. Never use plain SHA-256, SHA-1 or MD5 for passwords.
Does HTTPS encrypt everything?
HTTPS encrypts data between the browser and the server, including page content, form data and cookies. The domain name you visit can still be visible to networks in some cases, and data stored on the server is protected only by the server’s own security.