KSUID Generator & Decoder

Generate, decode, and validate KSUIDs in your browser

Free KSUID generator for K-Sortable Unique IDs. Mint a 27-character Base62 ID, pull the timestamp out of an existing one, or generate a batch. Everything stays in your browser.

Generating...

KSUID structure

Timestamp 32 bits / 4 bytes
Payload 128 bits / 16 bytes
20 bytes total, encoded as 27 Base62 characters

KSUID format

Length27 characters
EncodingBase62 (0-9A-Za-z)
Size160 bits (20 bytes)
Time unitSeconds
Epoch13 May 2014, 16:53:20 UTC
CaseCase-sensitive

KSUID vs ULID vs UUID

LengthKSUID 27, ULID 26, UUID 36
SortableKSUID and ULID yes, UUID v4 no
Time precisionKSUID seconds, ULID ms
Random bitsKSUID 128, ULID 80
Native DB typeUUID only

KSUID guide

What is a KSUID?

KSUID (K-Sortable Unique Identifier) is a 20-byte ID from Segment. The first four bytes count seconds from 13 May 2014, 16:53:20 UTC (1400000000 Unix). The other 16 bytes are random. Encoded with Base62, every KSUID is 27 characters.

Because time sits in the high bits, sorting KSUID strings is the same as sorting by creation time. That is the whole point: unique IDs that still work as a rough timeline.

Why 27 characters of Base62?

20 bytes is 160 bits. Base62 packs about 5.95 bits per character, so you need 27 characters to cover 160 bits. The string is padded on the left with 0 so the length never changes. That fixed width is what keeps lexicographic order aligned with time.

Base62 uses digits, uppercase, and lowercase. Unlike ULID, case matters. 0ujssw and 0UJSSW are different values.

KSUID vs ULID vs UUID

  • KSUID: second precision, 128 random bits, 27-character Base62. Fine when one ID per second is plenty and you want extra payload entropy.
  • ULID: millisecond precision, 80 random bits, 26-character Crockford Base32, case-insensitive. Pick this if you generate many IDs in the same second. Use the ULID Generator.
  • UUID v7: millisecond time in the RFC 9562 layout, native uuid columns. Use the UUID Generator.

For compact public slugs that do not need to sort, a NanoID is shorter. For 64-bit distributed IDs, see the Snowflake ID Decoder.

KSUID generator FAQ

What is a KSUID?

A KSUID is a 20-byte identifier: 4 bytes of time plus 16 random bytes. The string form is 27 Base62 characters. Segment shipped it so IDs could be unique and still sort by time.

How do I generate a KSUID online?

This page creates one on load. Click Generate for a new ID. Bulk Generate makes up to 100. Copy is one click. Generation uses crypto.getRandomValues() and never leaves the browser.

What is the difference between KSUID and ULID?

ULID timestamps are milliseconds and the string is Crockford Base32. KSUID timestamps are seconds, the epoch is 2014, and the string is Base62. ULID is a bit shorter and case-insensitive. KSUID has more random bits (128 vs 80).

Can I use KSUIDs as primary keys?

Yes. New IDs tend to land at the end of a B-tree, unlike random UUID v4. Store as CHAR(27) or 20 binary bytes. If you want a standard UUID type in Postgres, UUID v7 is less friction.

How do I get the timestamp from a KSUID?

Paste it into the decoder. The first four bytes are seconds after 13 May 2014, 16:53:20 UTC. Add 1,400,000,000 to get Unix seconds.

Is a KSUID case-sensitive?

Yes. Base62 includes both cases. Lowercasing a KSUID changes the ID. Do not treat it like a ULID.

When does the KSUID timestamp overflow?

The 32-bit counter runs out in 2150. That is far enough out that it is not a practical limit for systems being built now.