Generate KSUID

Generate a 27-character KSUID with an approximate creation-time sort order.

freeworks offlinenothing uploaded
ToolKSUID Generator
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

A KSUID stores a custom-epoch four-byte timestamp plus 16 random bytes, then encodes the 20 bytes as base62. The timestamp prefix makes values roughly sortable.

  • The 32-bit timestamp and 128 random bits balance compactness and collisions.
  • Base62 keeps the result URL-friendly.

Worked example

Single KSUID
Generate one K-Sortable Unique Identifier
Input
											1
										
Output
												3IPMnFOOj9keDZsC1hXTXGUoHyZ
											

When to use this

Event IDs, microservice resources, and non-sequential database keys use KSUIDs.

Edge cases

  • The custom epoch is not Unix epoch.
  • Same-second IDs sort by random suffix.
  • Base62 is case-sensitive and must not be lowercased.

References