Base32
Base32 is the base-32 numeral system. It uses a set of 32 digits, each of which can be represented by 5 bits (25). One way to represent Base32 numbers in a human-readable way is by using a standard 32-character set, such as the twenty-six upper-case letters A–Z and the digits 2–7. However, many other variations are used in different contexts.
This is an example of a Base32 number represented using the previously described 32-character set (IPFS CIDv1 in Base32 upper-case encoding): BAFYBEICZSSCDSBS7FFQZ55ASQDF3SMV6KLCW3GOFSZVWLYARCI47BGF354
Advantages
Base32 has a number of advantages over Base64:
- The resulting character set is all one case, which can often be beneficial when using a case-insensitive filesystem, DNS names, spoken language, or human memory.
- The result can be used as a file name because it cannot possibly contain the '/' symbol, which is the Unix path separator.
- The alphabet can be selected to avoid similar-looking pairs of different symbols, so the strings can be accurately transcribed by hand. (For example, the RFC 4648 symbol set omits the digits for one, eight and zero, since they could be confused with the letters 'I', 'B', and 'O'.)
- A result excluding padding can be included in a URL without encoding any characters.
Base32 also has advantages over hexadecimal/Base16:
- Base32 representation takes roughly 20% less space. (1000 bits takes 200 characters, compared with 250 for Base16).
Disadvantages
Base32 representation takes roughly 20% more space than Base64. Also, because it encodes 5 bytes to 8 characters (rather than 3 bytes to 4 characters), padding to an 8-character boundary is a greater burden on short messages.
Base64 | Base32 | |
---|---|---|
8-bit | 133% | 160% |
7-bit | 117% | 140% |
RFC 4648 Base32 alphabet
The most widely used Base32 alphabet is defined in RFC 4648. It uses an alphabet of A–Z, followed by 2–7. 0 and 1 are skipped due to their similarity with the letters O and I (thus "2" actually has a decimal value of 26).
In some circumstances padding is not required or used (the padding can be inferred from the length of the string modulo 8). RFC 4648 states that padding must be used unless the specification of the standard referring to the RFC explicitly states otherwise. Excluding padding is useful when using base32 encoded data in URL tokens or file names where the padding character could pose a problem.
Value | Symbol | Value | Symbol | Value | Symbol | Value | Symbol | |||
---|---|---|---|---|---|---|---|---|---|---|
0 | A | 8 | I | 16 | Q | 24 | Y | |||
1 | B | 9 | J | 17 | R | 25 | Z | |||
2 | C | 10 | K | 18 | S | 26 | 2 | |||
3 | D | 11 | L | 19 | T | 27 | 3 | |||
4 | E | 12 | M | 20 | U | 28 | 4 | |||
5 | F | 13 | N | 21 | V | 29 | 5 | |||
6 | G | 14 | O | 22 | W | 30 | 6 | |||
7 | H | 15 | P | 23 | X | 31 | 7 | |||
padding | = |
Alternative versions
Changing the Base32 alphabet, all alternative standards have similar combinations of alphanumeric symbols.
z-base-32
z-base-32[1] is a Base32 encoding designed to be easier for human use and more compact. It includes 1, 8 and 9 but excludes l, v and 2. It also permutes the alphabet so that the easier characters are the ones that occur more frequently. It compactly encodes bitstrings whose length in bits is not a multiple of 8, and omits trailing padding characters. z-base-32 was used in the Mnet open source project, and is currently used in Phil Zimmermann's ZRTP protocol, and in the Tahoe-LAFS open source project.
Value | Symbol | Value | Symbol | Value | Symbol | Value | Symbol | |||
---|---|---|---|---|---|---|---|---|---|---|
0 | y | 8 | e | 16 | o | 24 | a | |||
1 | b | 9 | j | 17 | t | 25 | 3 | |||
2 | n | 10 | k | 18 | 1 | 26 | 4 | |||
3 | d | 11 | m | 19 | u | 27 | 5 | |||
4 | r | 12 | c | 20 | w | 28 | h | |||
5 | f | 13 | p | 21 | i | 29 | 7 | |||
6 | g | 14 | q | 22 | s | 30 | 6 | |||
7 | 8 | 15 | x | 23 | z | 31 | 9 |
Crockford's Base32
Another alternative design for Base32 is created by Douglas Crockford, who proposes using additional characters for a checksum.[2] It excludes the letters I, L, and O to avoid confusion with digits. It also excludes the letter U to reduce the likelihood of accidental obscenity.
Libraries to encode binary data in Crockford's Base32 are available in a variety of languages.
Value | Encode Digit | Decode Digit | Value | Encode Digit | Decode Digit | |
---|---|---|---|---|---|---|
0 | 0 | 0 o O | 16 | G | g G | |
1 | 1 | 1 i I l L | 17 | H | h H | |
2 | 2 | 2 | 18 | J | j J | |
3 | 3 | 3 | 19 | K | k K | |
4 | 4 | 4 | 20 | M | m M | |
5 | 5 | 5 | 21 | N | n N | |
6 | 6 | 6 | 22 | P | p P | |
7 | 7 | 7 | 23 | Q | q Q | |
8 | 8 | 8 | 24 | R | r R | |
9 | 9 | 9 | 25 | S | s S | |
10 | A | a A | 26 | T | t T | |
11 | B | b B | 27 | V | v V | |
12 | C | c C | 28 | W | w W | |
13 | D | d D | 29 | X | x X | |
14 | E | e E | 30 | Y | y Y | |
15 | F | f F | 31 | Z | z Z |
Electrologica
An earlier form of base 32 notation was used by programmers working on the Electrologica X1 to represent machine addresses. The "digits" were represented as decimal numbers from 0 to 31. For example, 12-16 would represent the machine address 400 (= 12*32 + 16).
base32hex
Triacontakaidecimal is another alternative design for Base 32, which extends hexadecimal in a more natural way and was first proposed by Christian Lanctot, a programmer working at Sage software, in a letter to Dr. Dobb's magazine in March 1999[3] as a proposed solution for solving the Y2K bug and referred to as "Double Hex". This version was described in RFC 2938 under the name "Base-32". RFC 4648, while acknowledging existing use of this version in NSEC3, refers to it as base32hex and discourages labelling it as "base32".
Similarly to hexadecimal, the digits used are 0-9 followed by consecutive letters of the alphabet. This matches the digits used by the JavaScript parseInt()
function[4] and the Python int()
constructor[5] when a base larger than 10 (such as 16 or 32) is specified. It also retains hexadecimal's property of preserving bitwise sort order of the represented data, unlike RFC 4648's base-32 or base-64.[6]
Unlike many other base 32 notation systems, triacontakaidecimal is contiguous and includes characters that may visually conflict. With the right font it is possible to visually distinguish between 0, O and 1, I. Other fonts are unsuitable because the context that English usually provides is not provided by a notation system that is expressing numbers. However, the choice of font is not controlled by notation or encoding which is why it's risky to assume a distinguishable font will be used.
Value | Symbol | Value | Symbol | Value | Symbol | Value | Symbol | |||
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 9 | 9 | 18 | I | 27 | R | |||
1 | 1 | 10 | A | 19 | J | 28 | S | |||
2 | 2 | 11 | B | 20 | K | 29 | T | |||
3 | 3 | 12 | C | 21 | L | 30 | U | |||
4 | 4 | 13 | D | 22 | M | 31 | V | |||
5 | 5 | 14 | E | 23 | N | |||||
6 | 6 | 15 | F | 24 | O | |||||
7 | 7 | 16 | G | 25 | P | |||||
8 | 8 | 17 | H | 26 | Q | pad | = |
Geohash
See Geohash algorithm, used to represent latitude and longitude values in one (bit-interlaced) positive integer.[7] The base32 representation of Geohash use all decimal digits (0-9) and almost lower case alphabet, except letters "a", "i", "l", "o", as showed by the following character map:
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Base 32 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | b | c | d | e | f | g | |||
Decimal | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
Base 32 | h | j | k | m | n | p | q | r | s | t | u | v | w | x | y | z |
Video games
Before NVRAM became universal, several video games for Nintendo platforms used base 32 numbers for passwords. These systems omit vowels to prevent the game from accidentally giving a profane password. Thus, the characters are generally some minor variation of the following set: 0–9, B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z, and some punctuation marks. Games known to use such a system include Mario Is Missing!, Mario's Time Machine, Tetris Blast, and The Lord of the Rings (Super NES).
Software
Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers.
Base32 consists of a symbol set made up of 32 different characters, as well as an algorithm for encoding arbitrary sequences of 8-bit bytes into the Base32 alphabet. Because more than one 5-bit Base32 symbol is needed to represent each 8-bit input byte, it also specifies requirements on the allowed lengths of Base32 strings (which must be multiples of 40 bits). The closely related Base64 system, in contrast, uses a set of 64 symbols.
Base32 implementations in C/C++,[8][9] Perl,[10] Java,[11], JavaScript[12] Python[13], Go[14] and Ruby[15] are available.
See also
"Powers of 2" related bases: | Other bases: | Applications of base32:
|
References
- O'Whielacronx, Zooko (2009). "Human-oriented base-32 encoding".
- Douglas Crockford. "Base 32". Archived from the original on 2002-12-23.
- Lanctot, Christian (1999-03-01). "A Better Date? (second letter under that heading) - Letters". Dr Dobb's.
- "parseInt() - JavaScript". MDN Web Docs. Mozilla.
- "Built-in Functions". Python documentation. Python Software Foundation. Archived from the original on 2018-10-26. Retrieved 2017-08-09.
- Josefsson, Simon (2006). "7. Base 32 Encoding with Extended Hex Alphabet". RFC 4648: The Base16, Base32, and Base64 Data Encodings. IETF.
- "Tips & Tricks - geohash.org". geohash.org. Retrieved 2020-04-03.
- http://sourceforge.net/projects/cyoencode/
- https://www.gnu.org/software/gnulib/
- "MIME-Base32 - Base32 encoder and decoder". MetaCPAN. Retrieved 2018-07-29.
- https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base32.html
- https://www.npmjs.com/package/base32
- https://docs.python.org/3/library/base64.html
- https://golang.org/pkg/encoding/base32
- https://rubygems.org/gems/base32