UUID Generator
Pick a version to generate one. Every ID is produced in your browser and never leaves it.
- UUID v1 — Timestamp and MAC addressSortable, but reveals when and where it was made.
- UUID v2 — DCE securityNever fully specified. Avoid.
- UUID v3 — MD5 of a name in a namespaceDeterministic: the same input always gives the same UUID.
- UUID v4 — RandomThe default choice when you just need an identifier.
- UUID v5 — SHA-1 of a name in a namespaceDeterministic, and the more common of the two hashed versions.
- UUID v6 — v1 with the timestamp reorderedThe same fields as a v1, rearranged so they sort.
- UUID v7 — Unix timestamp and randomSorts by creation time. The best choice for database keys.
- UUID v8 — Whatever you wantRFC 9562 fixes six bits and leaves the other 122 to you.
Tools
- UUID decoderRead the version, variant and timestamp back out. Accepts canonical, braced, urn:uuid:, undashed and base64 input.
- Universal decoderPaste any ID and find out what it is: UUID, ULID, KSUID, TypeID, ObjectID or Snowflake.
- v7 time rangeBounds for querying a table by time when a v7 is the primary key.
- Compare ID formatsUUID against ULID, KSUID, Nano ID, Snowflake and the rest.
Generate one in code
A v4 is what you want in almost every case where you have not already decided otherwise.
TypeScript
// Built in to every current browser and to Node 19+.
crypto.randomUUID();Python
import uuid
uuid.uuid4()Go
import "github.com/google/uuid"
id := uuid.New()Rust
// uuid = { version = "1", features = ["v4"] }
use uuid::Uuid;
Uuid::new_v4();SQL (Postgres)
-- gen_random_uuid() is built in from Postgres 13.
SELECT gen_random_uuid();What is a UUID?
A UUID is a Universally Unique IDentifier: a 128-bit number used to identify something without coordinating with anyone else. It is usually written as 32 hexadecimal characters in five hyphenated groups.
UUIDs come in several versions. v4 is random, v1 and v6 encode a timestamp and a MAC address, v3 and v5 hash a name inside a namespace, and v7 encodes a Unix millisecond timestamp followed by random bits.
Why use UUIDs?
UUIDs can be generated anywhere, by anyone, with no central authority, and still be safely assumed not to collide. That makes them useful for distributed systems, offline clients, and merging data from separate databases.
They are also instantly recognisable, which makes them easy to pick out of logs.
Some databases (for example Postgres) store a UUID as a 128-bit integer rather than a 36-character string, so using one as a primary key costs far less than it looks.
What are the downsides?
Uniqueness is probabilistic, not guaranteed. The odds of two v4 UUIDs colliding are negligible, but they are not zero.
Some versions leak information. A v1 or v6 UUID contains the MAC address of the machine that generated it and the moment it was generated, which is enough to correlate a device across systems. You can see exactly what a UUID gives away with the UUID decoder.
Time-ordered IDs are also partly guessable, so they are a poor choice for anything that doubles as a secret, such as a password reset token.