Skip to content
BCBinary Code Translator
Menu

RFC 4648 URL-safe encoding

Base64url Encoder / Decoder

Encode UTF-8 text with the RFC 4648 URL-safe Base64 alphabet, decode padded or unpadded values, and clearly distinguish - and _ from ordinary Base64's + and /.

Encoding and decoding use local byte operations in this browser; no payload is sent to a server.

Conversion direction
0 characters
0 characters

Conversion runs locally in this browser. The input is not uploaded.

No result yet.

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

  1. Choose Encode when starting with text, or Decode when starting with a URL-safe Base64 string.
  2. For encoding, match the target protocol’s padding rule. JWT segments are usually unpadded, while another API may require equals signs.
  3. Paste the value without spaces. The decoder accepts A-Z, a-z, 0-9, hyphen, underscore, and valid trailing padding only.
  4. Check for - and _ when comparing against ordinary Base64. A value that contains + or / belongs to the standard alphabet and is rejected here.
  5. 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.

Base64url encoder and decoder FAQ

What is the exact difference between Base64 and Base64url?

Base64url replaces + with - and / with _. The six-bit grouping is otherwise the same. Padding policy depends on the protocol and is not inherently removed by the alphabet change.

Should Base64url include equals-sign padding?

RFC 4648 defines padding, but a referring specification may omit it when the length is known. Match the protocol you are implementing; this tool supports both output styles and decodes either valid form.

Can I paste a normal Base64 string here?

Only when it happens not to contain + or /. This decoder intentionally rejects those standard-alphabet characters so an accidental variant mismatch is visible.

Is Base64url safe to put directly in a URL?

Its alphabet is designed for URL and filename contexts, but the surrounding protocol may still impose length, delimiter, query, path, or percent-encoding rules. Follow that protocol's grammar.

Does decoding a JWT segment verify the token?

No. Base64url decoding only reveals bytes. JWT security requires signature verification and claim checks with an appropriate trusted key and library.

Why can a valid Base64url value fail UTF-8 decoding?

Base64url can represent signatures, encrypted data, compressed bytes, or arbitrary binary. This page displays text and therefore rejects decoded bytes that are not valid UTF-8.

Related encoding tools

View all tools

Cookie Preferences

Manage your cookie preferences. Necessary cookies cannot be disabled.

Necessary

Required

Required for language selection, privacy choices, and basic site functionality.

Cookies: NEXT_LOCALE

Analytics

Optional analytics cookies help us understand traffic and improve the website.

Cookies: _ga, _gid, _gat, _clck, _clsk

Advertising

Optional advertising cookies may be used to show relevant ads and measure performance.

Cookies: __gads, _gcl_au, IDE