UUID Generator
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit identifier that is guaranteed to be unique across all space and time. It is represented as a 32-character hexadecimal string divided into 5 groups by hyphens — for example:
UUIDs are defined by the RFC 4122 standard and come in several versions. Version 4 (v4) — the most commonly used — is generated using random or pseudo-random numbers, making the probability of a collision virtually zero.
Why Use UUIDs?
Globally Unique
UUIDs are unique across all systems worldwide — no central registry or coordination needed.
Database Primary Keys
Use UUIDs as primary keys to avoid conflicts when merging data from multiple sources or systems.
API Request IDs
Tag each API request with a unique UUID for tracing, debugging and logging purposes.
Distributed Systems
Generate IDs independently on any node without network coordination or race conditions.
Security
v4 UUIDs are unpredictable — making them suitable for tokens, session IDs and secret identifiers.
Testing & Mocking
Generate realistic unique IDs for test data, mock APIs and database seeding scenarios.
UUID v4 Format Explained
A v4 UUID follows this exact format — 8-4-4-4-12 hexadecimal characters separated by hyphens:
| Section | Length | Example | Notes |
|---|---|---|---|
| Time low | 8 chars | 550e8400 | Random in v4 |
| Time mid | 4 chars | e29b | Random in v4 |
| Version | 4 chars | 41d4 | Starts with 4 (version) |
| Variant | 4 chars | a716 | Starts with 8,9,a or b |
| Node | 12 chars | 446655440000 | Random in v4 |
Common Use Cases for UUID Generators
- Database primary keys (PostgreSQL, MySQL, MongoDB)
- REST API request and response identifiers
- Session tokens and authentication identifiers
- Microservices message and event IDs
- Transaction tracking and audit logging
- Test data generation and database seeding
- File and asset naming in cloud storage
- Idempotency keys for API requests
UUID vs Auto-Increment ID
| Factor | UUID (v4) | Auto-Increment |
|---|---|---|
| Uniqueness | ✅ Global | ❌ Local only |
| Distributed systems | ✅ No coordination needed | ❌ Requires central DB |
| Predictability | ✅ Unpredictable | ❌ Sequential — guessable |
| Merging databases | ✅ No conflicts | ❌ ID conflicts likely |
| Storage size | ❌ 36 chars (larger) | ✅ Small integer |
| Index performance | ❌ Slightly slower | ✅ Fast sequential index |
Frequently Asked Questions
What is a v4 UUID?
A v4 UUID is a randomly generated 128-bit identifier following the RFC 4122 standard. Unlike v1 (time-based) or v5 (name-based) UUIDs, v4 uses random numbers — making it the most commonly used version for general purpose unique ID generation.
Can two generated UUIDs ever be the same?
Theoretically yes, but practically no. With 2^122 possible v4 UUIDs, the probability of generating a duplicate is astronomically small — far less than a one in a trillion chance even after generating billions of UUIDs.
Are UUIDs safe to use as database primary keys?
Yes — UUIDs are widely used as primary keys, especially in distributed systems where multiple nodes need to generate IDs independently. The main trade-off is slightly larger storage and index size compared to integer IDs.
What is the difference between UUID and GUID?
GUID (Globally Unique Identifier) is Microsoft's implementation of UUID. They follow the same RFC 4122 standard and are functionally identical — the terms are interchangeable in most contexts.
Can I use UUIDs for security tokens?
v4 UUIDs can be used for non-critical tokens but for high-security use cases like password reset tokens or API keys, a cryptographically secure random generator is recommended instead — as UUID generation is not guaranteed to use a cryptographically secure source.
How do I generate a UUID in code?
Most languages have built-in UUID generation. In C# use Guid.NewGuid(), in JavaScript use crypto.randomUUID(), in Python use uuid.uuid4(), in Java use UUID.randomUUID(). Or just use FakeTools for instant generation without any code!