What is a UUID?
A UUID (universally unique identifier), also called a GUID in Microsoft tools, is a 128-bit ID written as 32 hexadecimal digits in five groups: 8-4-4-4-12. Version 4 UUIDs are random: 122 of the 128 bits come from a random generator, and the rest mark the version (4, the first digit of the third group) and variant (8, 9, a or b in the fourth group).
Can two UUIDs collide?
In practice, no. With 2122 possibilities, you'd need to generate about 2.7 quintillion UUIDs before there's even a 50% chance of a single duplicate.
Generate UUIDs in code
| Language | Code |
|---|---|
| JavaScript | crypto.randomUUID() |
| Python | import uuid; uuid.uuid4() |
| PostgreSQL | gen_random_uuid() |
| C# / .NET | Guid.NewGuid() |
| Command line (macOS/Linux) | uuidgen |
Need IDs that sort by creation time, for database keys? Look at UUID version 7, which starts with a timestamp.


