What Base64url changes from Base64
Base64url is the URL- and filename-safe alphabet defined in RFC 4648 section 5. It uses the same six-bit grouping as ordinary Base64, but replaces + with - and / with _. Those substitutions avoid characters that have special meanings in URLs, form encoding, paths, shells, and some filenames. The remaining letters and digits keep the same values.
Padding is a separate question from the alphabet. Standard Base64 normally uses trailing equals signs to make the character count a multiple of four. Many Base64url protocols, including common compact token formats, omit padding because the enclosing syntax already reveals the segment length. This page lets the encoder include or remove padding and lets the decoder accept either canonical form.
The input side is text-oriented: Unicode is encoded as UTF-8 before six-bit conversion, and decoded bytes must be valid UTF-8 before display. Base64url can also carry arbitrary binary content, so application code may need byte-level functions when working with signatures, compressed data, keys, or image bytes.
How to use the Base64url converter
- Choose Encode when starting with text, or Decode when starting with a URL-safe Base64 string.
- For encoding, match the target protocol’s padding rule. JWT segments are usually unpadded, while another API may require equals signs.
- Paste the value without spaces. The decoder accepts A-Z, a-z, 0-9, hyphen, underscore, and valid trailing padding only.
- Check for - and _ when comparing against ordinary Base64. A value that contains + or / belongs to the standard alphabet and is rejected here.
- Swap direction to verify UTF-8 recovery, then apply any protocol-specific parsing, signature verification, or schema validation separately.
Base64url examples and alphabet differences
Text vectors often look identical to ordinary Base64, so the byte examples deliberately include values that produce slash and plus in the standard alphabet. Padding is shown as a separate policy choice.
| Input | Output | Conversion direction | Notes |
|---|---|---|---|
Hello |
SGVsbG8= |
Encode | Include padding: With padding — Padded Hello. This text happens not to use the two alphabet characters that differ from ordinary Base64. |
Hello |
SGVsbG8 |
Encode | Include padding: Without padding — Unpadded Hello. RFC 4648 permits a referring specification to omit padding when the data length is known. |
SGVsbG8 |
Hello |
Decode | Decode either padding style. The decoder restores the required internal padding before reconstructing bytes. |
࠾ |
4KC- |
Encode | Include padding: With padding — URL-safe alphabet character. This valid UTF-8 character produces a trailing - in Base64url where ordinary Base64 uses +. |
你好 |
5L2g5aW9 |
Encode | Include padding: Without padding — Unicode UTF-8. Unicode text is converted to UTF-8 bytes before Base64url encoding. |
{"ok":true} |
eyJvayI6dHJ1ZX0 |
Encode | Include padding: Without padding — Compact JSON text. Encoding JSON does not sign, validate, or encrypt it; it only represents its UTF-8 bytes. |
Alphabet, padding, and valid lengths
The URL-safe alphabet consists of letters, digits, hyphen, and underscore. Padding may appear only as one or two equals signs at the end. Whitespace is rejected instead of stripped because URL segments and token components are normally contiguous, and silently removing characters can conceal a damaged copy.
An unpadded Base64url value may have a length remainder of zero, two, or three modulo four. A remainder of one cannot represent a whole number of bytes. When padding is supplied, its count must exactly restore a four-character block.
- Use - where ordinary Base64 would use +.
- Use _ where ordinary Base64 would use /.
- Trailing padding is optional for encoding but must be structurally correct when present.
- A plus sign, slash, embedded equals sign, or whitespace produces an error.
- Unused low bits in the final Base64 quantum must be zero for canonical input.
How Base64url converts UTF-8 bytes
The encoder reads three bytes, or twenty-four bits, at a time and divides them into four six-bit values. Each value selects one symbol from the Base64 alphabet. Base64url changes only the symbols at indexes sixty-two and sixty-three. If one or two source bytes remain, zero bits complete the temporary group and one or two equals signs may mark how many output bytes are absent.
For unpadded output, the encoder removes only those trailing equals signs; it does not remove data characters. The decoder calculates how much padding is implied by the length, maps - and _ back to the standard alphabet, reconstructs bytes, and verifies that any unused bits are zero. This is why simply accepting every alphanumeric-looking string can produce ambiguous representations.
After byte reconstruction, this page uses a fatal UTF-8 decoder. A browser’s permissive decoder may substitute U+FFFD for damaged bytes and make a failed conversion look successful. Strict decoding keeps the distinction between a valid Base64url byte sequence and valid Base64url text.
Common Base64url use cases
Base64url belongs inside protocols that need binary or structured data in a compact URL-safe text field. It does not provide confidentiality or authenticity, so security-sensitive protocols add signatures, MACs, encryption, or checksums separately.
| Use case | Description |
|---|---|
| JWT segments | JSON Web Tokens encode header and payload JSON, and usually signature bytes, as unpadded Base64url segments separated by dots. |
| OAuth and OIDC parameters | Nonce, state, PKCE, and signed request formats may use Base64url under a more specific protocol definition. |
| URL and filename identifiers | The alphabet avoids +, /, and percent-encoding in places where a compact byte-derived identifier is needed. |
| Web cryptography output | Keys, digests, signatures, and random bytes are often serialized as Base64url, but should remain byte arrays until the final presentation step. |
| API interoperability tests | Padding and alphabet differences are common causes of bugs between browser, server, and command-line implementations. |
Base64url errors and protocol boundaries
The most common failure is feeding ordinary Base64 directly into a Base64url parser. Replacing the alphabet characters may be sufficient at the raw encoding level, but an application must still know whether padding is permitted and what the decoded bytes mean.
A successfully decoded segment is not automatically trustworthy. For example, displaying a JWT payload does not verify its signature, issuer, audience, expiration, or algorithm. Encoding and protocol validation are separate layers.
- A length of one modulo four is impossible and is rejected.
- Padding in the middle or excessive padding is invalid.
- Standard Base64 + and / characters are rejected rather than normalized silently.
- Decoded binary data may not be UTF-8 text.
- Base64url is reversible and should never be described as encryption.
Base64url compared with Base64 and URL encoding
Ordinary Base64 and Base64url represent the same six-bit values with two different symbols. URL percent-encoding solves a different problem: it escapes characters in a URL component and does not convert arbitrary binary data into a compact alphabet.
Hexadecimal is easier to inspect and never needs padding, but it doubles the byte length. Base58 avoids several ambiguous characters but is less standardized for web protocols and uses different arithmetic.
| Use case | Description |
|---|---|
| Ordinary Base64 | Uses + and / and commonly keeps padding. Convert alphabets only when the target specification calls for Base64url. |
| URL percent-encoding | Escapes reserved URL characters such as spaces, ?, &, and =. It is not a Base64 variant. |
| JWT decoding | Reads token structure and JSON fields. A proper JWT workflow must also verify the cryptographic signature and claims. |