Base64 vs Base64URL: What's the Difference?

Base64URL is a URL-safe variant of Base64 encoding. While they work similarly, Base64URL uses different characters to avoid issues in URLs and filenames.

Key Differences

FeatureBase64Base64URL
Character 62+ (plus)- (hyphen)
Character 63/ (slash)_ (underscore)
PaddingRequired (=)Optional/omitted
URL SafeNo (needs escaping)Yes
Filename SafeNo (/ is invalid)Yes
RFCRFC 4648 §4RFC 4648 §5

Why the Different Characters?

The + Problem

In URLs, the + character has special meaning—it represents a space. When Base64 data containing + is placed in a URL, it gets misinterpreted:

// Original Base64:
SGVsbG8r
// In a URL query parameter:
?data=SGVsbG8r → decodes "+" as space → corrupted

The / Problem

The / character is a path separator in URLs and invalid in filenames. Including it in Base64 data breaks URL routing and file systems.

The = Problem

The = padding character is used for query parameter assignment in URLs. Base64URL typically omits padding entirely to avoid confusion.

Example Comparison

Encoding the same data with both methods:

Input:
>>>???
Standard Base64:
Pj4+Pz8/(contains + and /)
Base64URL:
Pj4-Pz8_(uses - and _)

When to Use Each

Use Base64URL for:

  • • JWT tokens
  • • URL query parameters
  • • Filenames
  • • Cookies
  • • OAuth tokens
  • • Any URL-embedded data

Use Standard Base64 for:

  • • Email attachments (MIME)
  • • Data URIs in HTML/CSS
  • • PEM certificates
  • • XML/JSON payloads
  • • Database storage
  • • When compatibility is critical

Converting Between Formats

Converting between Base64 and Base64URL is straightforward—just swap the characters:

// Base64 → Base64URL
base64url = base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
// Base64URL → Base64
base64 = base64url.replace(/-/g, '+').replace(/_/g, '/')
// Add padding if needed
while (base64.length % 4) base64 += '='

JWT and Base64URL

JSON Web Tokens (JWTs) use Base64URL encoding for their header and payload sections. This ensures the token can be safely passed in URLs, headers, and cookies without encoding issues.

eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.signature
↑ All three parts are Base64URL encoded

Try Both Formats

Our encoder/decoder supports both Base64 and Base64URL. Try them side by side to see the differences.

Open Encoder/Decoder →