KSUID generator and decoder
Generate KSUIDs — 27-character IDs that sort by creation time — with a secure random source, or paste a KSUID to see when it was made and what its random payload is. Everything runs in your browser.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Set How many (1 to 100). New KSUIDs are made at once; press Generate new for another set.
- Copy the list — one KSUID per line, sorted.
- To inspect an ID, paste it under Decode a KSUID: you get the creation time in UTC, the raw timestamp and the payload.
How it works
A KSUID is 20 bytes:
- bytes 0–3: seconds since the KSUID epoch (Unix time 1,400,000,000), big-endian;
- bytes 4–19: 128 random bits.
The 20 bytes are read as one 160-bit number and written in base 62 with the digits 0-9, A-Z, a-z, left-padded with 0 to 27 characters. The largest possible KSUID is aWgEPTl1tmebfsQzFP4bxwgy80V. Decoding runs the same steps backwards.
Worked example
The KSUID from the format’s documentation, 0ujtsYcgvSTl8PAuAdqWYSMnLOv, decodes to:
- timestamp 107608047 → Unix time 107,608,047 + 1,400,000,000 = 1,507,608,047;
- created 2017-10-10T04:00:47Z;
- payload B5A1CD34B5F99D1154FB6853345C9735.
Tips
- Store KSUIDs as text in a case-sensitive column: a and A are different digits.
- The creation time is visible to anyone holding the ID; do not use KSUIDs where that leaks information.
- For millisecond order, use a ULID; for standard compatibility, a UUID.
Frequently asked questions
What is a KSUID?
A K-Sortable Unique IDentifier, a format published by Segment. It is 20 bytes: a 4-byte timestamp in seconds and a 16-byte (128-bit) random payload, written as 27 base62 characters (0-9, A-Z, a-z). Because the time comes first, sorting KSUIDs as text sorts them by creation time.
Why does the timestamp not match Unix time?
KSUID counts seconds from its own epoch, 1,400,000,000 in Unix time (13 May 2014, 16:53:20 UTC), so a 32-bit counter lasts until the year 2150. Add 1,400,000,000 to the stored timestamp to get Unix time: 107,608,047 becomes 1,507,608,047, which is 10 October 2017, 04:00:47 UTC.
How does KSUID compare with UUID and ULID?
A UUID v4 has 122 random bits and no time order. A ULID has a 48-bit millisecond time and 80 random bits in 26 characters. A KSUID has only one-second time precision, but 128 random bits — more than either — so collisions are practically impossible even across many machines.
Are the IDs generated here random enough?
Yes. The payload comes from crypto.getRandomValues, the browser's cryptographically secure generator, and nothing is sent to a server. IDs made in the same second differ only in the payload, so the list is sorted for you.