Base64 encoding step by step

Published

Let’s encode the word Hi! and then Hi (which needs padding) by hand.

Example 1: “Hi!” (3 bytes, no padding)

Step 1 — characters to bytes. Using the ASCII table:

Character H i !
Decimal 72 105 33
Binary 01001000 01101001 00100001

Step 2 — join the bits:

010010000110100100100001

Step 3 — split into 6-bit groups:

010010 | 000110 | 100100 | 100001
  18   |    6   |   36   |   33

Step 4 — look up each number in the Base64 alphabet: 18 → S, 6 → G, 36 → k, 33 → h.

Result: Hi! → SGkh

Example 2: “Hi” (2 bytes, one = pad)

H        i
01001000 01101001

16 bits do not fill 24. Split into 6-bit groups and pad the last group with zero bits:

010010 | 000110 | 1001(00)
  18   |    6   |   36
   S   |    G   |    k

Only three characters carry data; one = marks the missing byte.

Result: Hi → SGk=

Example 3: “H” (1 byte, two = pads)

010010 | 00(0000)
  18   |    0
   S   |    A

Result: H → SA==

Non-ASCII text

Characters such as é or € are first converted to bytes with a character encoding, usually UTF-8. é becomes two bytes (C3 A9), so é encodes to w6k=. Different encodings give different Base64: in Windows-1252, é is one byte (E9) and encodes to 6Q==. That is why the text encoder lets you choose the character set.

Next: decoding step by step.

Comments (0)

Questions, ideas or a bug in “Base64 encoding step by step”? Leave a comment, rate the tool, or reply to others.

No comments yet. Be the first to share your feedback!

Leave a comment

Rate this tool:
Esc
↑ ↓ move↵ openEsc close