Skip to content
LangStop

Glossary

Keyboard Shortcuts

ActionShortcut
Toggle SidebarCtrl+B
Save TabCtrl+S
Close TabAlt+W
Switch to Tab 1Alt+Shift+1
Switch to Tab 2Alt+Shift+2
Switch to Tab 3Alt+Shift+3
Switch to Tab 4Alt+Shift+4
Switch to Tab 5Alt+Shift+5
Switch to Tab 6Alt+Shift+6
Switch to Tab 7Alt+Shift+7
Switch to Tab 8Alt+Shift+8
Switch to Tab 9Alt+Shift+9

Settings

Appearance

Customize the look and feel of the editor and interface.

Editor Theme

The font size used in the code editor.

14px

Space between lines in the editor.

1.6×

Changes apply instantly

What is a UUID? — Universally Unique Identifier Explained

Definition

A UUID (Universally Unique Identifier), also known as a GUID (Globally Unique Identifier) in Microsoft terminology, is a 128-bit identifier standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE) and later formalized in RFC 4122. UUIDs are designed to be unique across space and time — no two UUIDs should ever be the same, even when generated independently on different systems without centralized coordination.

UUIDs are widely used in software development for identifying resources, entities, records, and transactions where uniqueness must be guaranteed without a central authority.


UUID Format

A UUID is a 128-bit number typically represented as a 36-character string (32 hexadecimal digits separated by 4 hyphens) in the canonical 8-4-4-4-12 pattern:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Each x is a hexadecimal digit (0-9, a-f). Here is an example UUID:

550e8400-e29b-41d4-a716-446655440000

The 128 bits are divided into fields:

Field Bits Purpose
time_low 32 Timestamp low (v1) or random (v4)
time_mid 16 Timestamp middle (v1) or random (v4)
time_hi_and_version 16 Timestamp high (4 bits for version)
clock_seq_hi_and_reserved 8 Clock sequence + variant (2 bits)
clock_seq_low 8 Clock sequence low
node 48 MAC address (v1) or random (v4)

The variant field (2 bits in byte 8) indicates the UUID layout and interpretation. RFC 4122 specifies variant bits 10xx, which covers the vast majority of UUIDs in use today.

The version field (4 bits in byte 6) indicates which generation algorithm was used.


UUID Versions

RFC 4122 defines several UUID versions, each using a different strategy for generating a unique identifier.

UUID v1 — Time-Based

UUID v1 generates identifiers using the current timestamp (100-nanosecond intervals since October 15, 1582) combined with the generating machine's MAC address.

  • Source: Timestamp + clock sequence + MAC address
  • Uniqueness: High within a machine; global across machines via MAC
  • Privacy: Exposes the host MAC address and timestamp — a security concern
  • Speed: Fast, sequential
  • Collision risk: Near zero within the same machine
f47ac10b-58cc-1371-8567-0e02b2c3d479

Use case: Legacy systems, databases needing time-ordered indexing without v7 support.

UUID v3 — Name-Based (MD5)

UUID v3 generates identifiers by hashing a namespace UUID and a name string using MD5.

  • Source: MD5 hash of namespace UUID + name
  • Deterministic: Same name always produces the same UUID
  • Length: 128 bits (MD5 output)
  • Security: Not cryptographically secure
6ba7b810-9dad-31d0-80b4-00c04fd430c8

Use case: Generating deterministic identifiers from domain names, URLs, or object names within a known namespace.

UUID v4 — Random

UUID v4 generates identifiers using random or pseudo-random numbers. This is the most widely used UUID version.

  • Source: Random bytes (122 random bits, 6 fixed variant/version bits)
  • Uniqueness: Probabilistic — relies on random entropy
  • Privacy: No system information exposed
  • Speed: Very fast
  • Collision risk: Extremely low (see below)
550e8400-e29b-41d4-a716-446655440000

Use case: Primary keys in modern applications, session identifiers, API keys, event IDs, any scenario where anonymity and simplicity matter.

UUID v5 — Name-Based (SHA-1)

UUID v5 is identical in concept to v3 but uses SHA-1 instead of MD5 for hashing.

  • Source: SHA-1 hash of namespace UUID + name
  • Deterministic: Same name always produces the same UUID
  • Length: 128 bits (SHA-1 output truncated)
  • Security: Better than v3
6ba7b810-9dad-51d0-80b4-00c04fd430c8

Use case: Same as v3, but preferred over v3 because SHA-1 is more collision-resistant than MD5.

UUID v7 — Time-Ordered

UUID v7 is a newer version (proposed in RFC 9562) that combines a Unix timestamp in milliseconds with random data, producing identifiers that are sortable by time.

  • Source: Unix timestamp (ms) + random bits
  • Uniqueness: Timestamp + entropy
  • Ordering: Monotonically increasing — ideal for database indexes
  • Privacy: No MAC address exposure
  • Speed: Fast
018f3a6b-7a8c-7b00-b5e8-9e6c12d3f4a5

Use case: Modern database primary keys (especially in MySQL/PostgreSQL with clustered indexes), distributed tracing, event sourcing.


UUID Version Comparison

Feature v1 (Time) v3 (MD5) v4 (Random) v5 (SHA-1) v7 (Time-Ordered)
Bit length 128 128 128 128 128
Source Time + MAC Namespace + name Random Namespace + name Timestamp + random
Deterministic No Yes No Yes No
Time-ordered Yes (coarse) No No No Yes
Exposes MAC Yes No No No No
Database-friendly Moderate Poor Poor Poor Excellent
Collision resistance Very high Very high Extremely high Very high Very high
Standard RFC 4122 RFC 4122 RFC 4122 RFC 4122 RFC 9562
Speed Fast Moderate Very fast Moderate Very fast

UUID vs Other Identifier Formats

UUID vs ULID

ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier designed to be sortable and URL-safe.

Aspect UUID v4 UUID v7 ULID
Length 36 chars (with hyphens) 36 chars 26 chars (Crockford base32)
Sortable No Yes Yes
Timestamp No Unix ms (48 bits) Unix ms (48 bits)
Random 122 bits 74 bits 80 bits
Case-sensitive No (hex) No (hex) No (Crockford base32)
URL-safe Yes Yes Yes

ULIDs are preferred when you need compact, sortable identifiers without hyphens.

UUID vs Snowflake ID

Snowflake IDs (pioneered by Twitter/X) are 64-bit identifiers used in distributed systems.

Aspect UUID v4 Snowflake
Bit length 128 64
Storage 16 bytes 8 bytes
Sortable No Yes
Components Random Timestamp + worker ID + sequence
Coordination needed No Yes (worker ID assignment)
Generation rate Unlimited Limited per ms per worker

Snowflake IDs are ideal for high-throughput distributed systems where storage efficiency matters and worker coordination is feasible.

UUID vs NanoID

NanoID is a modern, URL-safe, compact unique ID generator.

Aspect UUID v4 NanoID
Length 36 chars 21 chars (default)
Alphabet Hex (16 chars) URL-safe (64 chars)
Entropy 122 bits ~126 bits (21-char default)
Sortable No No
Dependencies Crypto API Optional
Customizable No Yes (length, alphabet)

NanoID is preferred for URL shorteners, short public identifiers, and when you need compact tokens with a custom alphabet.


Collision Probability

The probability of a UUID collision depends on the version and the number of generated IDs.

UUID v4

UUID v4 uses 122 random bits. The probability of at least one collision after generating n UUIDs follows the birthday problem approximation:

  • After 2.71 trillion UUIDs: ~50% collision probability
  • After 1 billion UUIDs: ~0.0000000001% (essentially zero)
  • After 100 billion UUIDs: ~0.000001%

To put this in perspective: generating 1 billion UUIDs per second for the next 100 years would give you about a 50% chance of a single collision.

UUID v7

UUID v7 uses 74 random bits (plus a 48-bit timestamp). Within the same millisecond, there are 2⁷⁴ possible values — equivalent to v4's collision resistance on a per-millisecond basis.

Deterministic (v3/v5)

Collisions are theoretically possible but practically impossible when using unique namespace + name pairs with well-distributed hash functions.


The RFC 4122 Standard

RFC 4122 (July 2005) is the IETF standard that defines UUIDs. Key points:

  • Defines the UUID format, variant, and version fields
  • Specifies v1 (time-based), v3 (MD5 name-based), v4 (random), and v5 (SHA-1 name-based)
  • Defines four namespace UUIDs: DNS, URL, OID, and X.500
  • Updated by RFC 9562 (May 2024), which adds UUID v6, v7, and v8
  • Widely implemented in all major programming languages and operating systems

Common Use Cases

Database Primary Keys

UUIDs make excellent primary keys in databases, especially in distributed systems where auto-increment integers cannot guarantee uniqueness across shards or regions. UUID v7 is particularly well-suited because it is time-ordered and avoids index fragmentation.

Distributed Systems

In microservices and distributed architectures, services running on different nodes can generate UUIDs independently without synchronization — no central sequence server required.

Session Identifiers

UUID v4 is commonly used for web session IDs because it is random and reveals no information about the server or user.

API Keys

UUIDs serve as API keys, request correlation IDs, event IDs in event sourcing, and message IDs in message queues.

File and Asset Identifiers

Content management systems and cloud storage platforms use UUIDs to reference files, images, documents, and media assets without name collisions.


Generating UUIDs

Most programming languages include UUID generation in their standard libraries or have widely available third-party packages:

  • JavaScript/TypeScript: crypto.randomUUID() (Node.js 19+), uuid npm package
  • Python: uuid.uuid4(), uuid.uuid1(), uuid.uuid7() (Python 3.14+)
  • Java: java.util.UUID.randomUUID()
  • Go: github.com/google/uuid
  • Rust: uuid crate
  • PostgreSQL: gen_random_uuid(), uuid_generate_v4()
  • MySQL: UUID(), UUID_TO_BIN()
  • SQLite: randomblob(16) with formatting

LangStop UUID Tools

Related Tools

Try these complementary developer tools: