Base 64, Part 1: How and basics

Base 64 is an encoding method. It is used in many internet protocols and SMTP emails. One of the widest usage of base 64 in SMTP protocol is all binary file attachments are base 64 representation of its original data. It neither compress nor encrypt data, just encodes using the 64 alphabets shown in Table 1.

I would like to explain the basics of base 64 encoding in this blog, Part 2 of this blog will explain about Padding in Base 64.

Table 1: Base 64 Alphabets
Index Symbol
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 /
padding =

Lets look at the basics of base 64. For simplicity, take 3 letter the word ‘man’ to encode using base 64.

  1. Take the binary representation of each letter. m – 01101101, a – 01100001, n – 01101110
  2. Group 6-bits, you will get four 6-bits. The grouped bits are as follows 011011, 010110, 000101 and 101110
  3. Take the equivalent decimal value of each group, in our case we get 27, 22, 5 and 46
  4. Now check Table 1, take the symbols of the index what you got in the previous step. Thats it, encoding over. In our example we are getting bWFu, (27th symbol is b,22nd symbol is W,5th symbol is F and 46th symbol is u)

Permanent link to this article: https://blog.openshell.in/2012/10/how-base-64/

Leave a Reply

Your email address will not be published.