UUID Generator

Generate UUID v4, v7, NanoID, ULID and more

Loading...

About UUID Generator

A unique identifier is a value you can invent without asking anyone whether it is taken. This generator makes them in every shape that is in common use: UUIDs in all their versions, and the shorter formats that grew up around them when 36 characters with hyphens turned out to be more than some jobs needed. Everything is generated in your browser, from its cryptographic random source, and nothing is sent anywhere.

Which one should I use?

  • UUID v4 if you have no particular reason to choose otherwise. It is 122 random bits and it is what almost everything means by "a UUID".
  • UUID v7 if the ids become database keys. It carries the time in front, so a batch sorts in the order it was made and a B-tree index stops splitting pages at random.
  • NanoID if the id goes in a URL. Twenty-one characters carry more randomness than a v4 UUID does in thirty-six, with nothing that needs escaping.
  • ULID if the id will be read aloud or typed back in. Time-ordered like v7, with no I, L, O or U in its alphabet to be misread as 1, 0 or something rude.
  • UUID v5 if the same input must always produce the same id. It hashes a name rather than inventing anything.

UUID Format:

UUIDs are 32 hexadecimal digits, grouped into five sections separated by hyphens:xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

  • The "M" is the version, so a v4 UUID has a 4 there and a v7 has a 7
  • The "N" is one of 8, 9, A or B, which are the variant bits
  • That leaves 122 bits for the version to use as it sees fit

The UUID versions:

  • v1: the time and a node identifier. The node is normally a MAC address, which a browser cannot read, so a random one is used with the multicast bit set. That is what the standard asks for, and it means nobody mistakes it for a real network card.
  • v3: an MD5 hash of a name inside a namespace. Deterministic.
  • v4: random, and by far the most used.
  • v5: the same idea as v3 with SHA-1. Prefer it over v3.
  • v6: v1 with its fields reordered so the text sorts in time order. Useful for migrating away from v1; use v7 for anything new.
  • v7: 48 bits of Unix milliseconds, then randomness. The modern choice for database keys, and the one RFC 9562 added for exactly that.
  • Nil and Max: all zeros and all ones. The standard names them rather than generating them, and they are useful as sentinels.

The shorter formats:

  • NanoID: 21 characters from a 64-character URL-safe alphabet, which is 126 bits. Length and alphabet are both adjustable here.
  • ULID: 26 characters of Crockford base 32. 48 bits of milliseconds and 80 bits of randomness, monotonic within a millisecond so a batch keeps its order.
  • KSUID: 27 characters of base 62, letters and digits only. Four bytes of seconds counted from 2014 and sixteen random bytes.
  • MongoDB ObjectId: 24 hex characters. Four bytes of seconds, five that stand for whoever generated it, and a counter. What a Mongo _id holds when nothing sets one.

Common Use Cases:

  • Database Primary Keys: v7 or ULID, so the index stays tidy
  • Public URLs and share links: NanoID, for length
  • API Resource IDs: v4 or v7, whichever your stack already speaks
  • Test fixtures: ObjectId if the fixture is a Mongo document
  • Stable ids derived from a name: v5, so the same input gives the same id on every machine
  • Distributed Systems: any of them, which is the point: no coordination is needed

Free, unlimited, and generated locally. The same formats are available at the command line on this site: type uuid, nanoid, ulid, ksuid or objectid.