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. 1–9, A–H are the 17 encoded characters in order; 6-bit characters straddle 4-bit nibbles:

nnnn.nnnn.nnnn.nnnn.nnnn.1111.1122.2222-
3333.3344.4444.5555-
vvvv.5566.6666.7777-
uutt.8888.8899.9999-
AAAA.AABB.BBBB.CCCC.CCDD.DDDD.EEEE.EEFF.FFFF.GGGG.GGHH.HHHH
SymbolBitsRole
n20Name, not part of the data
v4UUID version, skipped
u2UUID variant, skipped
t2TNID variant: last 2 bits of character 7
1–9, A–H6 eachThe 17 encoded characters
CharactersBits
1–6First 40 payload bits
74 payload bits, then 2 TNID variant bits
8–17Last 60 payload bits

Worked example

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

#CharBitsValue
1B00110012
2r11011155
320000113
4f10101143
5l11000149
6c10100040
7N01100024
8D00111014
9f10101143
10F01000016
1160001117
12L01011022
13Y10001135
14I01001119
15C00110113
16n11001151
17T01111030

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