Skip to content
FreeAIDevTools

UUID v5 Generator

What a UUID v5 is, when to use it, and a generator scoped to this version. Runs in your browser.

What is a UUID v5? A UUID v5 is a name-based UUID: it hashes a namespace UUID plus a name with SHA-1 and keeps 122 bits of the hash, with 6 bits set for the version and variant. The same namespace and name always give the same UUID. The name www.example.com in the DNS namespace is 2ed6657d-e927-568b-95e1-2665a8aea6a2.

Version:
v5 is deterministic: the same namespace and name always give the same UUID.
Open the full UUID Generator →

The Inference Report · Every Tuesday

Know when AI prices change.

One short email every Tuesday: new models, price moves and free tiers that were cut or added. Five minutes, no fluff.

No spam. Unsubscribe anytime.

How is a UUID v5 calculated?

RFC 9562 spells out the recipe. Take the namespace ID, append the name as bytes, and run SHA-1 over the result. The first 128 bits of the 160-bit hash fill the UUID and the last 32 are dropped. Then 4 bits are overwritten with the version, 5, and 2 bits with the variant, which leaves 122 bits that come straight from the hash.

We ran the RFC's own example through the generator above. The DNS namespace with the name www.example.com returns 2ed6657d-e927-568b-95e1-2665a8aea6a2, the value in Appendix A.4 of RFC 9562, and Python's uuid.uuid5 returns the same one. That agreement is the point of v5: any correct implementation, in any language, derives the same ID.

The name is hashed byte for byte, so its format matters. www.example.com, WWW.example.com and www.example.com. with the trailing dot DNS allows give three different UUIDs. RFC 9562 notes that each name format within a namespace outputs a different UUID, so settle on one form, such as lowercase with no trailing dot, before you store any IDs.

When should you use UUID v5 instead of v4 or v7?

Use v5 when the same input has to produce the same ID every time, without a lookup table. Typical cases: a stable ID for a URL or an external record that two services compute on their own, an import that updates rows on a rerun instead of duplicating them, and deduplicating events by their content.

Use v4 or v7 for everything else. RFC 9562 says v4 should be used whenever a UUID plays any part in security, and anyone who knows the namespace and can guess the name can compute a v5. It also advises against name-based UUIDs as primary keys, because the value behind the name tends to change later. For new keys, v7 sorts by creation time and avoids both problems.

How do you generate a UUID v5 in Python, JavaScript, Java and Postgres?

Python ships it: uuid.uuid5(uuid.NAMESPACE_DNS, "www.example.com") takes the namespace first and the name second. The uuid package for JavaScript takes them the other way round, v5(name, namespace), and exposes the DNS and URL namespaces as v5.DNS and v5.URL. Pass them in the wrong order and both raise an error, because the namespace has to be a UUID.

Java's standard library has no v5 method: UUID.nameUUIDFromBytes returns a type 3 UUID, which uses MD5. Use a library, or build the value from a SHA-1 hash as RFC 9562 section 5.5 describes. In PostgreSQL, the uuid-ossp extension provides uuid_generate_v5(namespace, name), with uuid_ns_dns() and uuid_ns_url() for the standard namespaces.

Frequently asked

What are the UUID v5 namespaces?

RFC 9562 lists four: DNS 6ba7b810-9dad-11d1-80b4-00c04fd430c8, URL 6ba7b811-9dad-11d1-80b4-00c04fd430c8, OID 6ba7b812-9dad-11d1-80b4-00c04fd430c8 and X.500 6ba7b814-9dad-11d1-80b4-00c04fd430c8. For a namespace of your own, the RFC recommends generating a v4 or v7 UUID once and reusing it.

What is the difference between UUID v3 and v5?

The hash. v3 uses MD5 and v5 uses SHA-1, with the same namespace and name inputs, and RFC 9562 says v5 should be used instead of v3 where possible. The outputs differ: www.example.com in the DNS namespace is 5df41881-3aed-3515-88a7-2f4a814cf09e as a v3.

Can two UUID v5 values collide?

RFC 9562 promises that different names give different UUIDs with very high probability: 122 bits come from SHA-1, the same number of free bits as a random v4. The same name in the same namespace always gives the same UUID, by design. If SHA-1 is not allowed where you work, the RFC says to use a SHA-256 name-based UUID in the v8 space, not v5.

More in this series