Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

Base64URL Encode & Decode Online

Encode and decode URL-safe Base64, the variant used in JWTs, tokens and links. Choose padding or no padding, paste a JWT part to read it, and keep everything in your browser.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 BUTF-8
Base64URL
Runs in your browser. Nothing is uploaded. Tip: drop a file onto the left box

How to use the Base64URL tool#

  1. Choose Encode to turn text or a file into Base64URL, or Decode to read Base64URL, such as one part of a JWT.
  2. Type or paste into the left box. The result updates as you type.
  3. Turn on Add = padding only if the system you are sending to expects it. JWTs and most URLs use no padding.
  4. Copy the result, or download it. Decoding also accepts standard Base64 (+ and /), with or without =.

Examples#

Encode a JWT header

Input
{"alg":"HS256","typ":"JWT"}
Output
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

Every JWT starts with eyJ, because {" always encodes to those three characters.

Decode a JWT payload

Input
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
Output
{"sub":"1234567890","name":"John Doe","iat":1516239022}

This is the middle part of a JWT (between the two dots). It has no padding, which is normal for Base64URL.

See the difference from standard Base64

Input
???
Output
Pz8_

Standard Base64 gives Pz8/. The / would break a URL path, so Base64URL uses _ instead.

Short value without padding

Input
Hi
Output
SGk

Standard Base64 is SGk=. Base64URL usually drops the = because the decoder can work out the length.

What is Base64URL?#

Base64URL is a version of Base64 that is safe to put in URLs, file names and HTTP headers. It uses the same 64-character idea as standard Base64, but replaces the two characters that cause trouble in URLs: + becomes - and / becomes _. It usually leaves out the = padding as well. It is defined in RFC 4648, section 5, as "Base 64 Encoding with URL and Filename Safe Alphabet".

Like standard Base64, it turns every 3 bytes into 4 characters, so the output is about 33% larger than the input. It is an encoding, not encryption.

Why standard Base64 breaks in URLs#

Three characters of standard Base64 have special meanings in a URL:

CharacterMeaning in a URLWhat goes wrong
+A space in query strings (form encoding)The server decodes it as a space and the data is corrupted.
/Path separatorThe value is split into extra path segments.
=Separates a key from its valueIt has to be percent-encoded as %3D, which makes links longer and fragile.

Base64URL avoids all three, so the value can go into a URL path, a query string, a cookie or a file name without any extra escaping.

Base64 vs Base64URL#

Base64 (standard)Base64URL
Characters 0–61A–Z a–z 0–9A–Z a–z 0–9
Character 62+-
Character 63/_
PaddingRequired (=)Usually omitted
SpecRFC 4648 §4RFC 4648 §5
Typical useEmail, data URLs, PEM keysJWTs, tokens, URLs, file names

Converting between the two is a simple character swap: replace + with - and / with _, then remove or add the padding.

Padding in Base64URL#

The = signs at the end of standard Base64 only tell the decoder how many bytes the last group holds. That information can also be calculated from the length, so most Base64URL formats drop it:

  • Length remainder 2 (mod 4): the last group holds 1 byte (standard Base64 would add ==).
  • Length remainder 3: the last group holds 2 bytes (standard Base64 would add =).
  • Length remainder 1: impossible, so the input is broken.

JWTs (RFC 7515) require Base64URL without padding. Some other systems expect the padding to be kept, which is what the Add = padding option is for.

Base64URL in JWTs#

A JSON Web Token is three Base64URL strings joined by dots:

plaintext
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c└────────── header ──────────┘ └────────────────────────── payload ──────────────────────────┘ └────────── signature ──────────┘
  • The header and payload are JSON, so they decode to readable text.
  • The signature is raw bytes, so it decodes to binary data, not text. That is expected.

Decoding a JWT does not verify it. Anyone can read the payload, so never put secrets in it. To check the signature and expiry, use a JWT decoder and verifier.

Where Base64URL is used#

  • JWT, JWS and JWE: every part of the token.
  • OAuth 2.0 PKCE: the code_challenge is the Base64URL SHA-256 hash of the verifier, without padding.
  • WebAuthn and passkeys: credential IDs and challenges in JSON.
  • Signed URLs and invite links: tokens that sit in a URL path or query string.
  • File names and cache keys: identifiers that must not contain /.

Base64URL in code#

JavaScript (Node.js)#

javascript
const encoded = Buffer.from('Hi', 'utf8').toString('base64url'); // "SGk"const text = Buffer.from(encoded, 'base64url').toString('utf8');  // "Hi"

JavaScript (browser)#

javascript
function toBase64Url(bytes) {  return btoa(String.fromCharCode(...bytes))    .replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');} function fromBase64Url(str) {  const b64 = str.replace(/-/g, '+').replace(/_/g, '/');  const padded = b64 + '='.repeat((4 - (b64.length % 4)) % 4);  return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));}

PHP#

php
function base64url_encode(string $data): string{    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');} function base64url_decode(string $data): string|false{    return base64_decode(strtr($data, '-_', '+/'), true);}

Python#

python
import base64 encoded = base64.urlsafe_b64encode(b'Hi').rstrip(b'=').decode()   # "SGk" def b64url_decode(s: str) -> bytes:    return base64.urlsafe_b64decode(s + '=' * (-len(s) % 4))

Go#

go
encoded := base64.RawURLEncoding.EncodeToString([]byte("Hi")) // "SGk"decoded, err := base64.RawURLEncoding.DecodeString(encoded)

Common errors and fixes#

  • binascii.Error: Incorrect padding (Python)

    Base64URL values usually have no =, but Python's decoder requires it. Add the padding back first: s + "=" * (-len(s) % 4), then call base64.urlsafe_b64decode.

  • atob() fails with InvalidCharacterError on a JWT

    atob() only understands standard Base64, and the token contains - or _. Swap them for + and / and add the padding before calling atob(), or use the browser function shown above. This tool accepts both forms.

  • The signature part of a JWT decodes to random symbols

    That is correct. The signature is raw binary (an HMAC or RSA/ECDSA signature), not text. Only the header and payload are JSON.

  • A token works in a header but breaks when put in a URL

    It was encoded with standard Base64, and the +, / or = got changed in transit (often + turned into a space). Re-encode it as Base64URL.

  • "The input has N characters. That length is impossible"

    A Base64URL value can never leave exactly 1 character in its last group of 4. A character was lost while copying, often at the start or end of the token.

Frequently asked questions#

Is Base64URL the same as Base64?

Almost. Base64URL uses - and _ instead of + and /, and usually leaves out the = padding. Everything else, including the 33% size increase, is the same.

Does Base64URL use padding?

It depends on the format. RFC 4648 allows padding, but JWTs and most URL tokens leave it out because the length already tells the decoder how many bytes are in the last group. This tool decodes both.

How do I decode a JWT with this tool?

Copy the part between two dots (the header or the payload) and paste it in Decode mode. You will see the JSON. The signature part is binary, and decoding does not verify the token.

Why do all JWTs start with eyJ?

Every JWT header is a JSON object starting with {", and those two bytes always encode to eyJ in Base64URL.

Do I still need to URL-encode a Base64URL string?

No. Base64URL only uses letters, digits, - and _, which are all safe in URLs, so it can be used as-is in paths, query strings and file names.

Is it safe to paste a real JWT here?

Decoding runs entirely in your browser and nothing is uploaded. Still, treat live tokens like passwords: avoid sharing them, and prefer tokens that have already expired when testing.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.