Base32 (also known asduotrigesimal) is an encoding method based on thebase-32numeral system. It uses an alphabet of 32digits, each of which represents a different combination of 5bits (25). Since base32 is not very widely adopted, the question of notation—which characters to use to represent the 32 digits—is not as settled as in the case of more well-known numeral systems (such ashexadecimal), thoughRFCs and unofficial and de-facto standards exist. One way to represent Base32 numbers inhuman-readable form is using digits 0–9 followed by the twenty-two upper-case letters A–V. However, many other variations are used in different contexts. Historically,Baudot code could be considered a modified (stateful) base32 code. Base32 is often used to represent byte strings.
The October 2006 proposed Internet standard[1]RFC 4648 documentsbase16, base32 and base64 encodings. It includes two schemes for base32, but recommends one over the other. It further recommends that regardless of precedent, only the alphabet it defines in its section 6 actually be called base32, and that the other similar alphabet in its section 7 instead be called base32hex.[a] Agreement with those recommendations is not universal. Care needs to be taken when using systems that are called base32, as those systems could be base32 per RFC 4648 §6, or per §7 (possibly disregarding that RFC's deprecation of the simpler name for the latter), or they could be yet another encoding variant, see further below.
The most widely used[citation needed] base32 alphabet is defined in RFC4648 §6 and the earlierRFC 3548 (2003). The scheme was originally designed in 2000 by John Myers forSASL/GSSAPI.[2] It uses analphabet ofA–Z, followed by2–7. The digits0,1 and8 are skipped due to their similarity with the lettersO,I andB (thus "2" has a decimal value of26).
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 | = |
This is an example of a Base32 representation using the previously described 32-character set (IPFS CIDv1 in Base32 upper-case encoding):BAFYBEICZSSCDSBS7FFQZ55ASQDF3SMV6KLCW3GOFSZVWLYARCI47BGF354
"Extended hex" base 32 orbase32hex,[3] another scheme for base 32 per RFC4648 §7, extendshexadecimal in a more natural way: Its lower half is identical with hexadecimal, and beyond that, base32hex simply continues the alphabet through to the letter V.
This scheme was first proposed by Christian Lanctot, a programmer working atSage software, in a letter toDr. Dobb's magazine in March 1999[4] as part of a suggested solution for theY2K bug. Lanctot referred to it as "Double Hex". The same alphabet was described in 2000 inRFC 2938 under the name "Base-32". RFC 4648, while acknowledging existing use of this version inNSEC3, refers to it as base32hex and discourages referring to it as only "base32".
Since this notation uses digits 0-9 followed by consecutive letters of the alphabet, it matches the digits used by theJavaScriptparseInt()
function[5] and thePythonint()
constructor[6] 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 §6 base32, or base64.[3]
Unlike many other base 32 notation systems, base32hex digits beyond 9 are contiguous. However, its set of digits includes characters that may visually conflict. With the rightfont it is possible to visually distinguish between 0, O and 1, I, but other fonts may be unsuitable, as those letters could be hard for humans to tell apart, especially when the context English usually provides is not present in a notation system that is only expressing numbers.[b] The choice of font is not controlled by notation or encoding, yet base32hex makes no attempt to compensate for the shortcomings of affected fonts.[c]
Value | Symbol | Value | Symbol | Value | Symbol | Value | Symbol | |||
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 8 | 8 | 16 | G | 24 | O | |||
1 | 1 | 9 | 9 | 17 | H | 25 | P | |||
2 | 2 | 10 | A | 18 | I | 26 | Q | |||
3 | 3 | 11 | B | 19 | J | 27 | R | |||
4 | 4 | 12 | C | 20 | K | 28 | S | |||
5 | 5 | 13 | D | 21 | L | 29 | T | |||
6 | 6 | 14 | E | 22 | M | 30 | U | |||
7 | 7 | 15 | F | 23 | N | 31 | V | |||
padding | = |
Changing the Base32 alphabet, all alternative standards have similar combinations of alphanumeric symbols.
z-base-32[7] is a Base32 encoding designed byZooko Wilcox-O'Hearn to be easier for human use and more compact. It includes1,8 and9 but excludesl,v,0 and2. It also permutes the alphabet so that the easier characters are the ones that occur more frequently.[clarification needed] It compactly encodes bitstrings whose length in bits is not a multiple of 8[clarification needed] and omits trailing padding characters. z-base-32 was used in theMnet open source project, and is currently used inPhil Zimmermann'sZRTP protocol, and in theTahoe-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 |
Another alternative design for Base32 is created byDouglas Crockford, who proposes using additional characters for a mod-37 checksum.[8] 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 |
An earlier form of base 32 notation was used by programmers working on theElectrologica X1 to represent machine addresses. The "digits" were represented as decimal numbers from 0 to 31. For example,12-16 would represent the machine address400 (= 12 × 32 + 16).
SeeGeohash algorithm, used to represent latitude and longitude values in one (bit-interlaced) positive integer.[9] The base32 representation of Geohash uses all decimal digits (0–9) and almost all of the lower case alphabet, except letters "a", "i", "l", "o", as shown 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 |
BeforeNVRAM became universal, several video games forNintendo platforms used base 31 numbers forpasswords.These systems omit vowels (except Y) to prevent the game from accidentally giving aprofane 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 includeMario Is Missing!,Mario's Time Machine,Tetris Blast, andThe Lord of the Rings (Super NES).
The word-safe Base32 alphabet is an extension of theOpen Location CodeBase20 alphabet. That alphabet uses 8 numeric digits and 12 case-sensitive letter digits chosen to avoid accidentally forming words. Treating the alphabet as case-sensitive produces a 32 (8+12+12) digit set.
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Base 32 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | C | F | G | H | J | M | P | Q | |||
Decimal | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
Base 32 | R | V | W | X | c | f | g | h | j | m | p | q | r | v | w | x |
Base32 has a number of advantages overBase64:
Base32 has advantages overhexadecimal/Base16:
Compared with 8-bit-based encodings, 5-bit systems might also have advantages when used for character transmission:
Base32 representation takes roughly 20% more space thanBase64. Also, because it encodes five 8-bit bytes (40 bits) to eight 5-bit base32 characters rather than three 8-bit bytes (24 bits) to four 6-bit base64 characters, padding to an 8-character boundary is a greater burden on short messages (which may be a reason to elide padding, which is an option inRFC 4648).
Base64 | Base32 | Hexadecimal | |
---|---|---|---|
8-bit | 133% | 160% | 200% |
7-bit | 117% | 140% | 175% |
Even if Base32 takes roughly 20% less space thanhexadecimal, Base32 is much less used. Hexadecimal can easily be mapped to bytes because two hexadecimal digits is a byte. Base32 does not map to individual bytes. However, two Base32 digits correspond to ten bits, which can encode (32 × 32 =) 1,024 values, with obvious applications for orders of magnitude ofmultiple-byte units in terms of powers of 1,024.
Hexadecimal is easier to learn and remember, since that only entails memorising the numerical values of six additional symbols (A–F), and even if those are not instantly recalled, it is easier to count through just over a handful of values.
Base32programs are suitable for encoding arbitrary byte data using a restricted set of symbols that can both be conveniently used by humans and processed by computers.
Base32 implementations use a symbol set made up of at least 32 different characters (sometimes a 33rd for padding), as well as an algorithm for encoding arbitrary sequences of 8-bit bytes into a Base32 alphabet. Because more than one 5-bit Base32 character is needed to represent each 8-bit input byte, if the input is not a multiple of 5 bytes (40 bits), then it doesn't fit exactly in 5-bit Base32 characters. In that case, some specifications require padding characters to be added while some require extra zero bits to make a multiple of 5 bits. The closely related Base64 system, in contrast, uses a set of 64 symbols (or 65 symbols when padding is used).
Base32 implementations in C/C++,[10][11] Perl,[12] Java,[13] JavaScript[14] Python,[15] Go[16] and Ruby[17] are available.[18]
"Powers of 2" related bases: | Other bases: | Applications of base32:
|