What a UUID is
A UUID (Universally Unique Identifier) is a 128-bit value formatted as 32 hexadecimal digits in five groups: 550e8400-e29b-41d4-a716-446655440000.
UUIDs are used as database primary keys, session identifiers, file names, API tokens, and anywhere you need a unique value that can be generated without a central coordination system. Two independently generated UUIDs have an astronomically small probability of collision.
UUID versions explained
Version 4 (v4) — Random
UUID v4 is generated from 122 bits of cryptographic randomness. The remaining 6 bits indicate the version and variant. Example:
f47ac10b-58cc-4372-a567-0e02b2c3d479Version indicator: the 4 in the third group is always 4 for v4.
Use v4 for: database primary keys, session IDs, file identifiers, API keys — any situation where you need a unique identifier and sortability by creation time is not required.
Version 1 (v1) — Timestamp + MAC address
UUID v1 embeds the current timestamp (100-nanosecond intervals since October 15, 1582) and the MAC address of the generating machine. Example:
6ba7b810-9dad-11d1-80b4-00c04fd430c8Privacy concern: v1 UUIDs reveal when they were generated and can reveal the MAC address of the server that generated them. In 2023, this was implicated in identifying servers in several security disclosures.
Use v1 for: distributed systems where time-ordering of events matters and privacy is not a concern — for example, internal event logs where knowing the generation order is useful.
Version 7 (v7) — The modern choice
UUID v7 (standardized in 2022) combines a Unix timestamp prefix with random bits. It is sortable by creation time (like v1) but uses random bits instead of MAC addresses (safe like v4). It is the recommended choice for new systems that need time-ordered UUIDs.
Example: 018e6180-abcd-7abc-8def-012345678901 — the first 12 hex digits encode the Unix timestamp in milliseconds.
How to generate a UUID free
- Open the free UUID generator
- Select the version (v4 for most uses, v1 if you need timestamp ordering)
- Click Generate or copy one of the generated UUIDs
UUIDs are generated in your browser using the Web Crypto API (crypto.randomUUID() for v4) — nothing is sent to any server.
Using UUIDs as database primary keys
UUID primary keys have tradeoffs compared to sequential integer IDs:
- Pro: can be generated client-side before a database insert — useful for offline-capable apps and distributed systems
- Pro: does not reveal record count or creation order (security advantage)
- Con: larger storage size (16 bytes vs 4 bytes for int)
- Con: random UUIDs (v4) cause B-tree index fragmentation — inserts are slower on large tables. UUID v7 fixes this because its timestamp prefix keeps insertions roughly sequential.
Validating a UUID
A valid UUID matches this regex pattern:
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$Test UUID strings and other patterns with the free regex tester.
Summary
- v4: random, private, no ordering — use for most identifiers
- v1: timestamp + MAC address — time-ordered but reveals server identity
- v7: timestamp prefix + random — best of both, use for new systems needing time-sortable IDs
- Generate UUIDs free with the UUID generator — runs in your browser