Comparison

Standard Base64 vs Base64URL Encoding

Understand the critical differences between standard Base64 and the URL-safe Base64URL variant used in APIs and JWTs.

Published on August 19, 20265 min read

Base64 is the go-to standard for transmitting binary data over text-based protocols. However, the standard Base64 alphabet contains two characters that are strictly reserved in URLs and file systems: the plus sign (+) and the forward slash (/).

To solve this, a specialized variant called Base64URL (often referred to as URL-safe Base64) was introduced in RFC 4648.

The Problem with Standard Base64 in URLs

Imagine you want to send a Base64-encoded security token in a URL query parameter:

text
https://example.com/verify?token=aGVsbG8rc2VjcmV0/ZGF0YQ==

This URL will almost certainly break when processed by the server, because:

  • The Plus Sign (+): In URL query strings, a + is historically interpreted as a space character. When your server decodes the query parameter, aGVsbG8rc2VjcmV0/ZGF0YQ== becomes aGVsbG8 c2VjcmV0/ZGF0YQ==, which is corrupt and invalid Base64.
  • The Forward Slash (/): If you try to place the token in the URL path (e.g., /api/users/aGVsbG8rc2VjcmV0/ZGF0YQ==), the web server will treat the / as a directory separator, resulting in a 404 Not Found error.

The Solution: Base64URL

The Base64URL encoding scheme solves these problems by making exactly two substitutions to the standard Base64 alphabet:

  • The + character (Index 62) is replaced with a minus sign (-).
  • The / character (Index 63) is replaced with an underscore (_).

Base64 Index Table

0
A
1
B
2
C
3
D
4
E
5
F
6
G
7
H
8
I
9
J
10
K
11
L
12
M
13
N
14
O
15
P
16
Q
17
R
18
S
19
T
20
U
21
V
22
W
23
X
24
Y
25
Z
26
a
27
b
28
c
29
d
30
e
31
f
32
g
33
h
34
i
35
j
36
k
37
l
38
m
39
n
40
o
41
p
42
q
43
r
44
s
45
t
46
u
47
v
48
w
49
x
50
y
51
z
52
0
53
1
54
2
55
3
56
4
57
5
58
6
59
7
60
8
61
9
62
+
63
/
0-25: A-Z
26-51: a-z
52-61: 0-9
62-63: Symbols

What about the Padding (=)?

Standard Base64 uses the equals sign (=) for padding at the end of the string. While the equals sign is technically a safe character in a URL path, it carries special meaning in query strings (e.g., separating keys from values like key=value).

Because of this, Base64URL implementations typically omit the padding characters entirely. Since the length of the string is known, the decoder can dynamically calculate the missing padding and safely decode the string without the equals signs.

JSON Web Tokens (JWT)

If you work with modern web authentication, you are already using Base64URL.

A JSON Web Token (JWT) is composed of three parts separated by periods (.). The Header, Payload, and Signature are all encoded exclusively using Base64URL (with no padding). This guarantees that JWTs can be passed seamlessly in HTTP Headers (Bearer tokens), URL parameters, or POST bodies without requiring additional URL-encoding wrappers.

Convert to Base64URL Instantly

Need to generate a URL-safe token or decode a JWT payload? Use our dedicated Base64URL tool.

Open the Base64URL Tool