Disclosure: Some tools link to SaaS products we may earn a commission from — at no cost to you. All tools are free and run entirely in your browser. See full disclosure →
IDs
Output

Understanding UUIDs

A UUID (Universally Unique Identifier) is a 128-bit number standardised by RFC 4122. Unlike incrementing integers (1, 2, 3…), UUIDs are unique without coordinating with a central authority. They're essential in distributed systems where you can't rely on a single database to hand out sequential IDs.

UUID v4: Pure Randomness

UUID v4 is the most commonly used variant. It consists of 122 bits of random data and 6 bits of version/variant information. Because it's random, you can generate UUIDs independently on thousands of servers without worrying about collisions.

Best for: Database primary keys, API request tracking, session identifiers, temporary tokens, distributed system IDs.

UUID v7: Timestamp + Random

UUID v7 (introduced in 2023) combines a 48-bit timestamp with 80 bits of randomness. This makes UUIDs sortable by creation time — useful for databases where you want insertion-order locality without relying on auto-increment sequences.

Best for: Microservices with natural timeline tracking, event sourcing, time-series databases, leader election, any distributed system where order matters.

Nano ID: URL-Safe Alternative

Nano ID is a smaller alternative (21 characters vs 36 for UUID). It's URL-safe and uses a more efficient alphabet. While less standardised than UUID, it's gaining popularity in modern applications because it's shorter and doesn't require parsing.

Best for: URL slugs, short identifiers, applications where string length matters.

Practical Uses

Database Primary Keys

Instead of auto-increment integers, many modern databases use UUIDs. This lets you generate IDs on the client before inserting, useful for offline-first applications. Store as CHAR(36) or BINARY(16).

API Request IDs

Include a UUID in the X-Request-ID header of every API call. This helps with logging, debugging, and distributed tracing. Client generates it, server logs it, both use the same identifier to correlate requests across services.

Session & Token IDs

Web sessions, OAuth tokens, and temporary credentials often use UUIDs. They're random enough to prevent guessing and distributed enough for microservices.

Event & Log Correlation

In microservices, the same user action triggers events across multiple services. Attach a UUID to each "flow" and log it everywhere. Later, you can query all services by that UUID to see the complete transaction path.

UUID vs Other Identifiers

Type Format Sortable Distributed Best For
Auto-increment (1, 2, 3) 32-bit or 64-bit integer ✓ Yes ✗ No Single database, simple case
UUID v4 8-4-4-4-12 hex (36 chars) ✗ No ✓ Yes Distributed systems, multi-server
UUID v7 8-4-4-4-12 hex (36 chars) ✓ Yes ✓ Yes Modern distributed systems
Nano ID URL-safe alphanum (21 chars) ✗ No ✓ Yes URLs, short identifiers
ULID Crockford Base32 (26 chars) ✓ Yes ✓ Yes Sorted IDs with timestamps

Collision Probability

UUID v4 has 122 bits of entropy. The birthday paradox says you need roughly √(2^122) ≈ 2.71 × 10^18 IDs before a 50% collision chance. If you generate 1 billion per second, that's 86 million years. For practical purposes, collision is not a concern.

That said, don't use UUID as a cryptographic secret. It's not random-enough for security tokens. For those, use crypto.getRandomValues() or a server-side secret generator.

FAQ

Frequently Asked Questions

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify resources. The standard format is 8-4-4-4-12 hex digits separated by hyphens (e.g., 550e8400-e29b-41d4-a716-446655440000). UUIDs are used in databases as primary keys, for distributed system reconciliation, API request tracking, and anywhere you need a globally unique identifier without coordinating with a central authority.

What is the difference between UUID v4 and v7?

UUID v4 is random (128 bits of entropy, RFC 4122). UUID v7 is timestamp-based (48-bit millisecond timestamp + 80 bits of randomness). Use v4 when you want pure randomness and don't care about ordering. Use v7 when you want sortable IDs that reflect the time they were created — useful for databases where you want natural insertion order without database-assigned sequence numbers. v7 is newer (standardised in 2023) and favored in modern distributed systems.

Is UUID collision possible?

With UUID v4 (random), the probability of collision is negligible for practical purposes. You would need to generate 2.71 × 10^18 UUIDs before having a 50% chance of a single collision. For perspective, if you generated 1 billion UUIDs per second, it would take ~86 years to reach that threshold. In practice, collision is not a concern for v4.

Are these UUIDs cryptographically secure?

Yes. This generator uses JavaScript's Math.random() for v4 generation, which is suitable for non-cryptographic randomness. For cryptographic-grade randomness (e.g., generating tokens for security-sensitive applications), use the Web Crypto API (crypto.getRandomValues()), available in all modern browsers. Alternatively, generate security-critical IDs server-side.

Can I use UUIDs as API keys?

UUIDs are not cryptographically random enough for high-security API keys. Instead, use crypto.getRandomValues() with a sufficiently large byte array, or a dedicated secret-generation service. This tool is suitable for request IDs, database keys, and other non-security-critical identifiers.

How do I use UUIDs in my database?

Store UUIDs as CHAR(36) or BINARY(16). Most ORMs (Sequelize, Mongoose, TypeORM) have UUID column types. In PostgreSQL, use the uuid type. For performance, store as BINARY(16) to save space. When querying, either remove hyphens or normalize the format in your query layer. UUID indexes are as efficient as integer indexes for most use cases.

ID & Secret Generators
UUID v7 Generator Nano ID Generator Password Generator API Key Generator
💡
Need AI tools for your development workflow?

Explore our reviews of the best AI coding assistants, documentation generators, and developer productivity tools — ranked by real-world usefulness.

Browse AI Tools for Developers →
The DevTools Team
Infinfy Engineering
We build free developer utilities that we actually use ourselves. No accounts, no tracking, no backend — just fast, accurate, in-browser tools. Part of Infinfy Solutions.