Implementing

Data encoding

View this section in the spec ↗

Covers the 102 data bits (2 TNID variant + 100 payload), written as the 17 characters after the . in a TNID string: 17 characters × 6 bits.

Why 17 characters

The name has its own encoding and the 6 UUID version and variant bits are constants, leaving 102 bits. 102 = 17 × 6: no padding.

Alphabet

64 values, in ASCII order, so encoded strings sort like their bits:

-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

Value = position in this string, from 0. Full table under Mapping.

Not base64

Same 64 characters as base64url (RFC 4648), different order, so different output for the same bits. Don't use a base64 library.

String layout

One symbol per bit, one group per hex digit. 0–9, A–G are the 17 encoded characters in order; 6-bit characters straddle 4-bit nibbles:

nnnn.nnnn.nnnn.nnnn.nnnn.0000.0011.1111-
2222.2233.3333.4444-
vvvv.4455.5555.6666-
uutt.7777.7788.8888-
9999.99AA.AAAA.BBBB.BBCC.CCCC.DDDD.DDEE.EEEE.FFFF.FFGG.GGGG
SymbolBitsRole
n20Name, not part of the data
v4UUID version, skipped
u2UUID variant, skipped
t2TNID variant: last 2 bits of character 6
0–9, A–G6 eachThe 17 encoded characters
CharactersBits
0–5First 36 payload bits
64 payload bits, then 2 TNID variant bits
7–16Last 60 payload bits

Worked example

Data part of user.Br2flcNDfF6LYICnT = d6157337-0ebc-8686-83ab-4075a34cdcde. Character 6, N = 011000, ends in 00: TNIDv0.

#CharBitsValue
0B00110012
1r11011155
220000113
3f10101143
4l11000149
5c10100040
6N01100024
7D00111014
8f10101143
9F01000016
1060001117
11L01011022
12Y10001135
13I01001119
14C00110113
15n11001151
16T01111030

Mapping

Read each column top to bottom.

000000 -   010000 F   100000 V   110000 k
000001 0   010001 G   100001 W   110001 l
000010 1   010010 H   100010 X   110010 m
000011 2   010011 I   100011 Y   110011 n
000100 3   010100 J   100100 Z   110100 o
000101 4   010101 K   100101 _   110101 p
000110 5   010110 L   100110 a   110110 q
000111 6   010111 M   100111 b   110111 r
001000 7   011000 N   101000 c   111000 s
001001 8   011001 O   101001 d   111001 t
001010 9   011010 P   101010 e   111010 u
001011 A   011011 Q   101011 f   111011 v
001100 B   011100 R   101100 g   111100 w
001101 C   011101 S   101101 h   111101 x
001110 D   011110 T   101110 i   111110 y
001111 E   011111 U   101111 j   111111 z