Base64 Encoder & DecoderSpecialized Version
🔐

Base64 URL Encoder

Base64 URL Encoder

Base64 URL Encoder

Encode data to URL-safe Base64 format with our free online encoder. URL-safe Base64 uses - and _ instead of + and /, making it safe for use in URLs, filenames, and other contexts where standard Base64 characters cause problems.

Why URL-Safe Base64?

Standard Base64 uses + and / characters which have special meanings in URLs and file paths:

  • + becomes a space in URL query strings
  • / is a path separator in URLs and filesystems
  • = padding can cause issues in some parsers
URL-safe Base64 solves these problems by substituting these characters.

Standard vs URL-Safe Comparison

| Feature | Standard Base64 | URL-Safe Base64 | Character 63/_ Padding= (required)Often omitted URL safeNoYes Filename safeNoYes Cookie safeNoYes

Encoding Examples

InputStandardURL-Safe Hello?SGVsbG8/SGVsbG8_ data+1ZGF0YSsxZGF0YSsx | test== | dGVzdD09 | dGVzdD09 |

Implementation

``javascript // Encode to URL-safe Base64 function toBase64Url(text) { const base64 = btoa(encodeURIComponent(text).replace( /%([0-9A-F]{2})/g, (_, p1) => String.fromCharCode(parseInt(p1, 16)) )); return base64 .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, ''); }

// Decode URL-safe Base64 function fromBase64Url(base64url) { let base64 = base64url .replace(/-/g, '+') .replace(/_/g, '/'); // Add padding if needed while (base64.length % 4) { base64 += '='; } return decodeURIComponent(atob(base64).split('').map( c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) ).join('')); }

// Node.js native support const encoded = Buffer.from('Hello').toString('base64url'); const decoded = Buffer.from(encoded, 'base64url').toString(); ``

Common Use Cases

  • JWT Tokens: Header and payload are Base64URL encoded
  • URL Parameters: Safely pass encoded data in query strings
  • OAuth State: Encode state parameters for OAuth flows
  • Filenames: Create safe filenames from arbitrary data
  • Cookies: Store encoded data in cookies without escaping
  • Short URLs: Encode IDs for URL shorteners

Tips for URL-Safe Base64

1. Check the checkbox in our encoder to enable URL-safe mode 2. Padding is optional - many implementations omit trailing = signs 3. Same data, different output - standard and URL-safe are interchangeable if you convert the characters 4. JWT uses URL-safe - all modern JWT libraries expect Base64URL encoding

Frequently Asked Questions

What is URL-safe Base64?

URL-safe Base64 replaces + with - and / with _ to avoid conflicts with URL special characters. It may also omit the = padding. This allows Base64 data to be used directly in URLs, filenames, and cookies without additional encoding.

Can I convert between standard and URL-safe Base64?

Yes, they represent the same data. To convert standard to URL-safe: replace + with -, / with _, and optionally remove = padding. To convert URL-safe to standard: replace - with +, _ with /, and add = padding until length is divisible by 4.

Does Base64 provide encryption?

No, Base64 is encoding, not encryption. It transforms data format but provides no security whatsoever. Anyone can decode Base64 data instantly. For security, use actual encryption (AES, RSA) before Base64 encoding.

Related Tools

Explore other tools you might find useful:

Related Calculators