Guides

Encoding vs hashing vs encryption, with examples

Encoding, hashing and encryption all turn readable data into something that looks scrambled, which is why they get confused. They do completely different jobs. Encoding changes how data is written so it survives transport, hashing produces a fingerprint you cannot reverse, and encryption hides data so only someone with the key can read it. Mixing them up is how passwords end up "protected" with Base64.

By Radhika Singh · Last updated

At a glance

The two questions that separate them: can it be reversed, and does reversing it need a secret?

Reversible?Needs a key?PurposeExamples
EncodingYes, by anyoneNoRepresent data safely for a channelBase64, URL encoding, HTML entities
HashingNoNoFingerprint: detect changes, look up, store passwordsSHA-256, MD5
Keyed hashing (HMAC)NoYes, shared secretProve a message came from someone with the keyWebhook signatures, TOTP codes
EncryptionYes, with the keyYesConfidentialityAES, RSA, TLS

Encoding: same data, different alphabet

Encoding rewrites data in a form a particular channel accepts. Base64 writes any bytes using 64 safe characters, so Hello becomes SGVsbG8=; it grows data by about a third (4 characters for every 3 bytes), which is why a large image as a Base64 data URL is a poor idea (Image to Base64 shows the size, and Base64 to Image decodes one back). URL encoding writes characters that have meaning in a URL as percent codes: a space becomes %20 and & becomes %26 (URL Encoder). HTML entities do the same for markup, so < becomes &lt; (HTML Entity Encoder).

Unicode escapes such as \u00e9 for é let code and JSON carry any character in plain ASCII (Unicode Escape), and number bases are encoding at the smallest scale: 255 is FF in hex and 11111111 in binary (Number Base Converter).

None of this hides anything. Anyone can decode Base64 in a second, so a password or API key in Base64 is a password in plain text.

Hashing: a fingerprint you cannot reverse

A hash function turns input of any size into a fixed-size value, always the same for the same input and completely different after any change. The SHA-256 hash of hello is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824; change one letter and every character changes. You cannot get hello back from it, only check whether a guess produces the same hash.

That makes hashes ideal for checking downloads against a published checksum and for spotting changed files, which is what the Hash Generator is for: it computes MD5, SHA-1, SHA-256, SHA-384 and SHA-512 at once and compares against an expected value. MD5 and SHA-1 are broken for security (collisions can be manufactured; a practical SHA-1 collision was published in 2017) but still fine for catching accidental corruption.

Passwords are the exception: never store them with a fast hash like SHA-256, because fast is exactly what an attacker wants. Use a slow, salted password hash such as Argon2, bcrypt or scrypt, which your framework's authentication library already provides.

HMAC and TOTP: hashing with a secret

An HMAC mixes a secret key into the hash, so only someone holding the key can produce the right value. Webhook providers sign each request this way (GitHub's X-Hub-Signature-256 header is an HMAC-SHA-256 of the body), and your server recomputes the signature to confirm the request is genuine. The HMAC Generator computes and verifies signatures while you build that check.

TOTP, the six-digit codes in authenticator apps, is an HMAC of the current 30-second time step under a secret shared once through a QR code (RFC 6238). The TOTP Generator is for testing two-factor sign-in in apps you build; real account secrets belong in an authenticator app, not a web page.

Encryption: hiding data behind a key

Encryption is the only one of the four that provides confidentiality. Symmetric ciphers such as AES use one key to encrypt and decrypt; public-key systems such as RSA and elliptic-curve cryptography encrypt with a public key that only the matching private key can undo. HTTPS uses both: public-key cryptography to agree on a key, then AES or ChaCha20 for the data. Encryption belongs in vetted libraries and protocols, not in a web tool, which is why this site has none.

IDs and slugs are none of these

Identifiers are often mistaken for hashes because they look random. A version 4 UUID is 122 random bits, unique in practice and meaningless by design (UUID Generator). Version 7, standardized in RFC 9562 (May 2024), puts a millisecond timestamp in front, so new IDs sort in creation order and keep database indexes compact (UUID v7 Generator). A URL slug is just a readable version of a title, lowercased and hyphenated (Slug Generator); it identifies a page, it does not protect anything.

Rules of thumb

When you are unsure which one a job needs:

  • Data has to survive a URL, an email or JSON: encode it.
  • You need to know whether something changed: hash it.
  • You need to know who sent it: HMAC it with a shared secret, or sign it.
  • Nobody else should be able to read it: encrypt it, with a standard library.
  • Storing passwords: a slow password hash (Argon2, bcrypt, scrypt), never Base64 and never plain SHA-256.

The tools in this guide

Found a mistake? Write in from the About page and it gets fixed.

Pick a tool.
Get it done.

125 utilities today, more every month. Bookmark the one you reach for.