Guides › Base64, URL Encoding, HEX/ASCII and JWT Explained
Base64, URL Encoding, HEX/ASCII and JWT Explained
Encoding represents data in a different form. It is not encryption: anyone can reverse it. The goal is not secrecy but moving data safely through systems that accept only certain characters.
Base64
Base64 represents binary data with 64 characters: upper and lowercase letters, digits, + and /. It is used wherever binary data must travel through text-only channels: email attachments, images inside JSON, HTTP Basic auth, logged MQTT payloads.
How it works
- Group the input into 3 bytes (24 bits).
- Split the 24 bits into four 6-bit pieces.
- Map each 6-bit value (0-63) to a character: 0-25 → A-Z, 26-51 → a-z, 52-61 → 0-9, 62 → +, 63 → /
- If the last group is short, pad with
=.
"Man" → 4D 61 6E → 010011 010110 000101 101110 → T W F u → "TWFu" "Hello" → "SGVsbG8=" "한" → UTF-8 bytes ED 95 9C → "7ZWc"
- Output is about 33% larger than the input (3 bytes → 4 characters).
- Base64URL replaces
+and/with-and_and usually drops padding, so it is safe in URLs and file names. JWT uses it. - Non-ASCII text must be converted to UTF-8 bytes first. The browser
btoa()function throws on such characters.
URL encoding (percent-encoding)
URLs allow only a limited character set (RFC 3986). Other characters are written as their byte values in %XX form.
- Unreserved characters, safe as-is:
A-Z a-z 0-9 - _ . ~ - Reserved characters with special meaning:
: / ? # [ ] @ ! $ & = + , ;and others; encode them when they appear inside a value.
| Character | Encoded | Notes |
|---|---|---|
| space | %20 (+ in form submissions) | Mixing the two causes frequent bugs |
& | %26 | Clashes with the query separator |
= | %3D | Clashes with the key/value separator |
/ | %2F | Clashes with the path separator |
| é | %C3%A9 | Each UTF-8 byte is encoded |
In JavaScript use encodeURIComponent() for a single query value and encodeURI() for a whole URL. Encoding an already-encoded value produces double encoding such as %25C3....
HEX and ASCII
ASCII assigns numbers 0-127 to letters, digits, symbols and control characters. HEX writes each byte as two hexadecimal digits (00-FF). Viewing serial or Modbus traffic as HEX reveals invisible control characters exactly.
| HEX | Char | HEX | Char | HEX | Char |
|---|---|---|---|---|---|
| 00 | NUL | 20 | space | 41 | A |
| 02 | STX (start of text) | 30 | 0 | 5A | Z |
| 03 | ETX (end of text) | 39 | 9 | 61 | a |
| 06 | ACK | 3A | : | 7A | z |
| 0A | LF (line feed) | 2C | , | 7B / 7D | { / } |
| 0D | CR (carriage return) | 2E | . | 22 | " |
| 15 | NAK | 2D | - | 7F | DEL |
- Digit characters 0-9 are 0x30-0x39; subtract 0x30 to get the numeric value.
- Upper and lowercase letters differ by 0x20 (A = 0x41, a = 0x61).
- Windows line endings are CR LF (
0D 0A); Linux uses LF (0A). If a device ignores your command, check the line ending. - Characters outside ASCII take several bytes in UTF-8 (é =
C3 A9, 한 =ED 95 9C).
JWT (JSON Web Token)
A JWT carries login state or permissions between systems (RFC 7519). It has three parts separated by dots.
xxxxx.yyyyy.zzzzz Header.Payload.Signature
| Part | Content | Example |
|---|---|---|
| Header | Token type and signing algorithm | {"alg":"HS256","typ":"JWT"} |
| Payload | Claims (the data) | {"sub":"user123","exp":1764403600} |
| Signature | Header and payload signed with a key | Detects tampering |
The header and payload are Base64URL-encoded JSON, so anyone can decode and read them. This site's JWT decoder shows them right in your browser without a server.
Registered claims
| Claim | Meaning |
|---|---|
| iss | Issuer |
| sub | Subject (usually the user ID) |
| aud | Audience (the service meant to accept the token) |
| exp | Expiration time (Unix seconds) |
| nbf | Not valid before this time |
| iat | Issued at |
Security notes
- A JWT is signed, not encrypted. Never put passwords or personal data in the payload.
- Servers must verify the signature and
exp. Decoding without verifying accepts forged tokens. - Reject
"alg":"none"tokens and pin the allowed algorithms on the server. - Do not paste live production tokens into untrusted sites. This site's decoder works only inside your browser and sends nothing to a server.
Encoding vs encryption vs hashing
| Kind | Reversible | Purpose | Examples |
|---|---|---|---|
| Encoding | By anyone | Format conversion | Base64, URL encoding, HEX |
| Encryption | Only with the key | Confidentiality | AES, RSA |
| Hashing | No (one-way) | Integrity, password storage | SHA-256, bcrypt |
| Error-detecting code | Not applicable | Detect transmission errors | CRC |
Tools: Base64 · URL encoder · HEX-ASCII · JWT decoder
Try it now: Base64 Encoder / Decoder (runs in your browser, no data is sent anywhere)