Developers and curious users constantly meet strings of odd-looking characters and have to decide what they are. A password stored in Base64, for example, is a serious mistake that comes from confusing two very different ideas. Encoding, hashing and encryption solve separate problems, and knowing which is which prevents real security failures.
The one-minute summary
- Encoding changes how data is represented, so it can travel safely through a system. Anyone can reverse it, and there is no secret.
- Hashing produces a fixed-size fingerprint of data. It is designed to be one-way.
- Encryption scrambles data so that only someone holding the right key can read it.
The useful question is always: "Is there a secret involved, and is the process meant to be reversible?"
Base64: moving binary data through text channels
Many systems were designed to carry text. Base64 represents arbitrary bytes using only 64 safe characters: A-Z, a-z, 0-9, + and /, with = used for padding. Three bytes of input become four characters of output, so the result is around 33% larger than the original.
Base64 appears in e-mail attachments, images embedded directly in web pages, data fields in JSON and the header and payload of JSON Web Tokens. A variant called Base64URL replaces + and / with - and _, so it can sit inside addresses without extra escaping.
Base64 has no key and no secrecy. If you see a Base64 string in a browser, an API response or a configuration file, anybody can decode it in a second. A JWT's payload is the classic example: it may be signed, but unless it has also been encrypted, its contents can be read by anyone who has the token.
URL encoding: making text safe in addresses
Web addresses only allow a limited set of characters. Others are written as a percent sign followed by hexadecimal values. A space becomes %20 and the Turkish letter ş, stored in UTF-8 as two bytes, becomes %C5%9F.
Encoding the right part matters. A question mark or ampersand inside a search value has to be encoded, or the server will read it as the separator between parameters. Encoding an entire address, on the other hand, also escapes the characters that give the address its structure and breaks it. Double encoding is another common bug, where %20 becomes %2520 because the same value was encoded twice.
HTML entities: a similar idea for a different context
HTML uses a related technique. Characters that have special meaning in markup are written as entities, such as < for < and & for &. This is important for security: text from users has to be properly escaped when placed in a page, or a visitor may be able to inject scripts. Each context, whether HTML, a URL, or JavaScript, has its own escaping rules, and using the wrong one offers little protection.
Hashing: fingerprints of data
A hash function takes input of any size and produces a fixed-length value. SHA-256 always yields 256 bits, written as 64 hexadecimal characters. Changing a single letter of the input gives a completely different result. You cannot directly recover the input from a good cryptographic hash.
Typical uses are verifying downloads, detecting changed files and supporting digital signatures. If you compare the SHA-256 checksum of a file with the value published by its author, a match shows the file has not been altered, as long as you obtained that value from a trustworthy source.
MD5 and SHA-1 are broken for security purposes, because attackers can deliberately produce two inputs with the same hash. They remain acceptable for non-security tasks, such as a quick check for accidental duplication, but not for anything that needs to resist an attacker.
Storing passwords is a special case
A fast hash such as SHA-256 is the wrong tool for passwords, precisely because it is fast: attackers can test billions of guesses. Password storage calls for deliberately slow algorithms with a unique random salt for each user, such as Argon2, scrypt or bcrypt. The salt ensures two users with the same password get different stored values and defeats precomputed lookup tables.
Encryption: keeping information secret
Encryption is reversible, but only with the right key. Symmetric algorithms such as AES use the same key to encrypt and decrypt, and are fast. Asymmetric algorithms such as RSA and elliptic-curve systems use a pair of public and private keys, which helps two parties establish trust and exchange a key. HTTPS combines the two.
Do not design your own encryption and do not rely on tricks such as rotating letters. ROT13 and the Caesar cipher are fun for puzzles but provide no protection. Use established libraries, keep keys separate from the data they protect and rotate them when exposed.
Choosing correctly
- Need to fit binary data into a text field? Base64.
- Need to put text inside a link? URL encoding.
- Need to show user text safely in a page? HTML escaping.
- Need to verify that a file has not changed? A cryptographic hash.
- Need to store a password? A slow, salted password hash.
- Need to protect data so it can be read later by authorised people? Encryption.
When a value looks scrambled, do not assume it is protected. Ask how it was produced and what, if anything, would be needed to reverse it.