Skip to content

Commit 715be88

Browse files
code-atomSiteleaf
authored andcommitted
Added Difference Between Base64 And Base64url
1 parent 13fe610 commit 715be88

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: Difference between Base64 and Base64URL
3+
date: 2025-09-02 23:42:00 +05:30
4+
categories:
5+
- jwt
6+
- web
7+
tags:
8+
- encoding
9+
- general
10+
layout: post
11+
---
12+
13+
Base64 and Base64url are both encoding schemes used to represent binary data in an ASCII string format, but they differ in how they handle certain characters to ensure compatibility with specific environments, particularly URLs.
14+
15+
## **Base64**
16+
17+
- **Purpose:**
18+
19+
Standard Base64 is a general-purpose encoding scheme for converting binary data into a text format that can be safely transmitted over channels designed for text, such as email or XML documents.
20+
21+
- **Character Set:**
22+
23+
It uses 64 characters for encoding: A-Z, a-z, 0-9, `+` (plus sign), and `/` (forward slash). It also uses `=` (equals sign) for padding at the end of the encoded string to ensure the length is a multiple of 4.
24+
25+
```
26+
Table 1: The Base 64 Alphabet
27+
28+
Value Encoding Value Encoding Value Encoding Value Encoding
29+
0 A 17 R 34 i 51 z
30+
1 B 18 S 35 j 52 0
31+
2 C 19 T 36 k 53 1
32+
3 D 20 U 37 l 54 2
33+
4 E 21 V 38 m 55 3
34+
5 F 22 W 39 n 56 4
35+
6 G 23 X 40 o 57 5
36+
7 H 24 Y 41 p 58 6
37+
8 I 25 Z 42 q 59 7
38+
9 J 26 a 43 r 60 8
39+
10 K 27 b 44 s 61 9
40+
11 L 28 c 45 t 62 +
41+
12 M 29 d 46 u 63 /
42+
13 N 30 e 47 v
43+
14 O 31 f 48 w (pad) =
44+
15 P 32 g 49 x
45+
16 Q 33 h 50 y
46+
```
47+
48+
- **Limitations in URLs:**The `+`, `/`, and `=` characters have special meanings in URLs and can cause issues if not properly percent-encoded, which adds complexity and increases the length of the URL.
49+
50+
### **Base64URL**
51+
52+
- **Purpose:** Base64url is a variant of Base64 specifically designed to be "URL-safe," meaning it avoids characters that are problematic in URLs.
53+
- **Character Set:**It modifies the standard Base64 character set:
54+
- The `+` character is replaced with  (hyphen/minus).
55+
- The `/` character is replaced with `_` (underscore).
56+
- Padding with `=` is often omitted or handled implicitly, as its presence can also cause issues in some URL contexts. The length of the encoded string can be used to determine if padding would be needed during decoding.
57+
58+
```
59+
Table 2: The "URL and Filename safe" Base 64 Alphabet
60+
61+
Value Encoding Value Encoding Value Encoding Value Encoding
62+
0 A 17 R 34 i 51 z
63+
1 B 18 S 35 j 52 0
64+
2 C 19 T 36 k 53 1
65+
3 D 20 U 37 l 54 2
66+
4 E 21 V 38 m 55 3
67+
5 F 22 W 39 n 56 4
68+
6 G 23 X 40 o 57 5
69+
7 H 24 Y 41 p 58 6
70+
8 I 25 Z 42 q 59 7
71+
9 J 26 a 43 r 60 8
72+
10 K 27 b 44 s 61 9
73+
11 L 28 c 45 t 62 - (minus)
74+
12 M 29 d 46 u 63 _
75+
13 N 30 e 47 v (underline)
76+
14 O 31 f 48 w
77+
15 P 32 g 49 x
78+
16 Q 33 h 50 y (pad) =
79+
```
80+
81+
- **Advantages in URLs:**By using  and `_` instead of `+` and `/`, and by handling padding differently, Base64url eliminates the need for additional percent-encoding when embedding encoded data directly within URLs, making them cleaner and easier to handle.
82+
83+
### **Summary**
84+
85+
The core difference lies in the substitution of two characters (`+` and `/` with `-` and `_` respectively) and the handling of padding, all to make Base64url suitable for direct inclusion in URLs without requiring further encoding. While standard Base64 is widely used for general binary-to-text encoding, Base64url is preferred when the encoded data needs to be part of a URL, such as in JSON Web Tokens (JWTs) or other URL-based data structures.
86+
87+
Reference:
88+
89+
- [https://stackoverflow.com/questions/55389211/string-based-data-encoding-base64-vs-base64url](https://stackoverflow.com/questions/55389211/string-based-data-encoding-base64-vs-base64url)

0 commit comments

Comments
 (0)