GameParticles
Random & generators

What Is a UUID? Structure, Versions and Collision Odds

What is a UUID? A 128-bit identifier written as 36 characters that can be generated anywhere without coordination. Learn its structure, versions and odds.

Updated

A UUID (universally unique identifier) is a 128-bit number used to label something, such as a database row, a file or a request, so that the label will not clash with any other, even one created on a different machine at the same moment. It is written as 32 hexadecimal digits in five hyphenated groups, for example f47ac10b-58cc-4372-a567-0e02b2c3d479. No central authority hands them out; any computer can create one on its own.

Why UUIDs exist

The traditional identifier is a counter: 1, 2, 3. A counter needs one place that knows the last number issued, which works for a single database and gets awkward everywhere else. Two servers, an offline mobile app, or two companies merging their data will all produce a second record numbered 1001.

A UUID removes the coordination. Each generator picks from a space so large that independent choices do not collide in practice. That lets a client create an ID before the server has seen the record, lets databases merge without renumbering, and avoids revealing how many records exist, which sequential IDs do.

Structure

The text form has 36 characters laid out as 8-4-4-4-12:

f47ac10b-58cc-4372-a567-0e02b2c3d479

Two positions carry meaning in every UUID:

  • The version is the first digit of the third group. In the example it is 4, so this is a version 4 UUID.
  • The variant is the first digit of the fourth group. For the standard variant it is always 8, 9, a or b. The example has a.

The remaining bits depend on the version: random data, a timestamp, a hash, or a mixture. The format is defined by RFC 9562, published in 2024, which replaced the earlier RFC 4122 from 2005.

Hex digits are case insensitive. The RFC recommends writing lowercase and accepting either. The hyphens are part of the standard text form but carry no information, so many systems store the 32 digits alone or the raw 16 bytes.

UUID vs GUID

A GUID is a UUID. Microsoft adopted the design under the name globally unique identifier, and the term stuck across Windows, COM, .NET and SQL Server. Guid.NewGuid() in .NET returns a version 4 UUID.

The differences are presentational:

  • GUIDs are often shown in uppercase, and in the Windows registry and some APIs wrapped in braces: {F47AC10B-58CC-4372-A567-0E02B2C3D479}.
  • When a GUID is stored as 16 raw bytes, Microsoft's layout writes the first three groups in little-endian order. Reading those bytes on a system that expects the RFC's big-endian order shows the first three groups with their bytes reversed. If an ID looks scrambled only in its first half after crossing systems, this is the cause.

As text, a UUID and a GUID are interchangeable.

Versions at a glance

VersionBuilt fromTypical use
1Timestamp plus a node ID, originally the MAC addressOlder systems. Reveals time and possibly the machine
2DCE security variant of version 1Rare
3MD5 hash of a namespace and a nameDeterministic IDs. Version 5 is preferred
4122 random bitsThe general-purpose default
5SHA-1 hash of a namespace and a nameDeterministic IDs: the same input always gives the same UUID
6Version 1 fields reordered so values sort by timeMigration path for version 1 users
7Unix timestamp in milliseconds plus random bitsDatabase keys that should sort by creation time
8Custom layout defined by the applicationExperimental or vendor-specific schemes

RFC 9562 also defines two special values: the nil UUID, which is all zeros, and the max UUID, which is all f digits. Both are used as placeholders or sentinels, never as real IDs.

Two versions cover most needs. Version 4 is pure randomness and is what you get from crypto.randomUUID() in browsers and Node.js, uuid.uuid4() in Python and gen_random_uuid() in PostgreSQL. Version 7 puts a timestamp first so new IDs sort in creation order, which databases prefer. The trade-offs between them are covered in UUID v4 vs v7.

Versions 3 and 5 are different in kind: they are not random at all. They hash a namespace UUID together with a name, so the URL https://example.com/a always maps to the same UUID. That is useful for giving stable IDs to things that already have a natural name. For the hash functions behind them, see MD5 vs SHA-256.

Collision odds

A version 4 UUID has 122 random bits; the other 6 are fixed for the version and variant. That gives 2 to the power 122 possible values, about 5.3 undecillion, a number with 37 digits.

The relevant question is not whether one specific UUID is repeated, but whether any two in a set match, which is the birthday problem. The numbers are still enormous:

  • Generate about 103 trillion version 4 UUIDs and the chance that any two match is roughly one in a billion.
  • To reach a 50 percent chance of one collision you would need about 2.7 quintillion of them. At a billion UUIDs per second, that takes around 86 years.

For any realistic application, the count of IDs you will ever create is nowhere near these figures. Real-world duplicates come from other causes: a random number generator seeded identically on cloned virtual machines, code that copies a record along with its ID, or a column that truncates the value.

UUIDs are unique, not secret. A version 4 UUID from a cryptographic generator is hard to guess, but other versions embed timestamps or hashes of known inputs. Do not treat an ID as an access token unless you know exactly how it was generated.

Storing and using UUIDs

  • Use a native type where one exists. PostgreSQL's uuid type and a BINARY(16) column take 16 bytes; the same value as text takes 36.
  • Normalize case and format at the boundary. Compare F47AC10B... with f47ac10b... as strings and they differ, although they are the same UUID.
  • Validate the shape with a pattern such as ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ in case-insensitive mode. The regex cheat sheet explains each piece.

Generating UUIDs

Most platforms have a built-in generator: crypto.randomUUID() in JavaScript, uuid.uuid4() in Python, uuidgen on macOS and Linux, New-Guid in PowerShell, UUID.randomUUID() in Java.

When you need a handful for test fixtures, seed data or a config file, the UUID Generator produces version 4 UUIDs in batches of 1 to 100, with options for uppercase and for removing the hyphens, which gives the 32-character form some GUID fields expect. It generates version 4 only. For IDs that double as security tokens, generate them in your application with the platform's cryptographic API instead.

Try it

Open the UUID Generator, choose how many you need, and copy them out. Look at the first digit of the third group in each one: it is always 4, and the first digit of the fourth group is always 8, 9, a or b, exactly as the structure above describes.

Tools in this guide

Frequently asked questions

What is a GUID?

GUID stands for globally unique identifier. It is Microsoft's name for the same 128-bit value that standards documents call a UUID. Windows, .NET and SQL Server use the term GUID, and their generators produce values that follow the UUID layout.

What is the difference between a UUID and a GUID?

There is no difference in the value itself. The differences are habits: GUIDs are often shown in uppercase and wrapped in braces, and Microsoft's binary layout stores the first three fields in little-endian byte order, which matters when raw bytes move between systems.

Can two UUIDs ever be the same?

In theory yes, in practice no. A version 4 UUID has 122 random bits, so you would need to generate about 103 trillion of them before the chance of a single duplicate reached one in a billion. A broken random number generator is a far likelier cause.

How long is a UUID?

A UUID is 128 bits, or 16 bytes. Its standard text form is 36 characters: 32 hexadecimal digits plus four hyphens, grouped 8-4-4-4-12. Without hyphens it is 32 characters. Stored as binary it takes 16 bytes.

More random & generators guides

JSON Formatter
Developer · Format, validate and minify JSON with syntax highlighting.
↵
Base64 Encode / Decode
Developer · Encode text to Base64 or decode Base64 back to plain text.
↵
URL Encoder / Decoder
Developer · Encode or decode URL components and query strings.
↵
Hash Generator
Developer · Generate MD5, SHA-1, SHA-256 and SHA-512 hashes.
↵
UUID Generator
Developer · Generate UUIDs v4 (random) in bulk with one click.
↵
Regex Tester
Developer · Test regular expressions against text with live match highlighting.
↵
Word Counter
Text · Count words, characters, sentences, paragraphs and reading time.
↵
Case Converter
Text · Convert text between UPPER, lower, Title, camelCase, snake_case and more.
↵
List Sorter
Text · Sort, reverse, deduplicate and shuffle lists of text.
↵
Markdown Preview
Text · Write Markdown and see a live rendered preview side by side.
↵
Percentage Calculator
Numbers · Calculate percentages, increases, decreases and what % one number is of another.
↵
Color Converter
Colors · Convert colors between HEX, RGB, HSL and HSV instantly.
↵
Snake
Arcade · Eat food, grow longer, don't hit the walls. A timeless classic.
↵
2048
Puzzle · Slide tiles and combine them to reach the legendary 2048 tile.
↵
Word Grid
Puzzle · Guess the hidden five letter word in six tries using color clues.
↵
Sudoku
Puzzle · Fill the 9x9 grid with logic. Four difficulties from easy to expert.
↵
Minesweeper
Strategy · Use number clues to clear the minefield. Classic logic, three levels.
↵
Breakout
Arcade · Smash every brick with paddle and ball. Power-ups, combos, endless levels.
↵
Typing Practice
Casual · Build your WPM and accuracy with timed drills from 30 seconds to 5 minutes. Find your weak keys.
↵
TypeRunner
Arcade · Multiplayer typing race. Race friends by link, beat computer runners, or chase your own ghost.
↵
Typing Blocks
Arcade · Type each word before its wooden block lands. Miss, and the pile climbs toward the line.
↵
Bubble Shooter
Arcade · Aim, bank shots off the walls, and pop groups of three or more bubbles.
↵
Road Rush
Arcade · Race seven rivals through traffic and punch your way to the front.
↵