Base32 Encoding

https://en.wikipedia.org/wiki/Base32

You can encode binary data into Base32 using various methods depending on the programming language you're using. Base32 encoding represents binary data in a text format using 32 printable ASCII characters.

Base32 Alphabet

Pasted image 20250319000246.png

Base32 encoding uses the following 32 characters:

ABCDEFGHIJKLMNOPQRSTUVWXYZ234567

It does not use numbers 0 and 1 to avoid confusion with letters O and I.


Encoding Steps

  1. Convert Binary to 5-bit Chunks

    • Base32 represents data in 5-bit chunks.
    • Pad with 0 bits if necessary to form complete 5-bit groups.
  2. Map to Base32 Alphabet

    • Each 5-bit chunk is mapped to a Base32 character.
  3. Add Padding (=) if Needed

    • If the original data isn't a multiple of 5 bits, padding (=) is added.

Example in Python

Python provides base64 module, which supports Base32:

import base64

data = b'hello'  # Binary data
encoded = base64.b32encode(data)
print(encoded.decode())  # Output: NBSWY3DP

Example in JavaScript

const { encode } = require('hi-base32');

const binaryData = Buffer.from("hello");
console.log(encode(binaryData)); // Output: NBSWY3DP

Would you like a specific implementation in another language?