Skip to content

Base32 encoding

Greg Bowler edited this page Apr 19, 2026 · 1 revision

Throughout the library, a base32 alphabet is used for converting numbers.

The public Base32 class is useful when we want to work with the encoding directly, or when we want to understand why the generated IDs avoid certain characters.

Why 32?

Base64 is a commonly used encoding type. The "64" part of Base64 means that there are 64 different characters available for encoding. That's A-Z upper and lower case, 0-9, and a few symbols.

Base32 includes numbers 0-9 and an upper-case alphabet, minus some ambiguous characters.

Identifiers are often copied by people:

  • from a terminal
  • from a browser address bar
  • from a support ticket
  • from a printed label

This library deliberately avoids ambiguous characters such as:

  • I
  • L
  • O
  • U

That reduces mistakes when reading or typing an identifier.

Encoding a number

use GT\Ulid\Base32;

$base32 = new Base32();
echo $base32->fromDec(105);

Decoding back to decimal

$number = $base32->toDec("39");
var_dump($number);

The important point is that the encoding is reversible within the library's rules.

Where this shows up in normal usage

Most of the time we do not call Base32 ourselves. Ulid uses it internally to:

  • encode the timestamp section
  • encode each random value in the random section

Extractor also uses it to decode timestamp strings back into integers.

Custom skipped characters

The constructor allows a different skip-character list:

$base32 = new Base32("ilou");

That is the default used by the library itself.

In practice, changing it would only make sense if the whole application controls both encoding and decoding and has a good reason to diverge from the default alphabet.


To see the pieces together in small, practical scripts, continue with Examples.

Clone this wiki locally