UUID Generator
Generate random UUIDs (v4).
A UUID (Universally Unique Identifier) is a 128-bit identifier formatted as 32 hex digits in 5 groups separated by hyphens โ for example, 550e8400-e29b-41d4-a716-446655440000. UUID v4 is randomly generated, making collisions statistically impossible across distributed systems. To generate a UUID online: click Generate UUID above for a single v4 UUID, or specify a count to generate multiple at once. Common uses: primary keys in databases, request trace IDs, session tokens, and unique file names. Generation uses your browser's crypto.randomUUID() API โ no data is transmitted.
What is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit number used to uniquely identify information in computer systems. This tool generates Version 4 UUIDs, which are completely random.
How Unique is it?
The probability of generating a duplicate UUID is virtually zero. To put it in perspective, you would need to generate 1 billion UUIDs every second for 85 years to have a 50% chance of a single collision.
Use Cases
- Database Keys: Using UUIDs as primary keys allows for easy data merging from different sources.
- Session IDs: Unique identifiers for user sessions in web applications.
- File Naming: Preventing filename collisions in uploaded files.
UUID Versions Explained
While this tool generates v4 UUIDs, it's helpful to understand the different versions:
- Version 1 (Time-based): Uses current timestamp and MAC address. Sequential and sortable, but can expose hardware information and is predictable.
- Version 3 (MD5 Hash): Creates UUIDs from a namespace and name using MD5 hashing. Deterministicโsame input always produces the same UUID.
- Version 4 (Random): Purely random generation. Recommended for most applications due to unpredictability and simplicity. This is what our tool generates.
- Version 5 (SHA-1 Hash): Like v3 but uses SHA-1 instead of MD5. More secure and also deterministic.
Most applications should use v4 for simplicity and security. Use v1 only if you need time-sortable UUIDs. Use v5 if you need deterministic IDs from the same input.
Why Use UUIDs Instead of Auto-Increment IDs?
Traditional auto-increment IDs (1, 2, 3...) work well for single-database systems, but UUIDs offer significant advantages:
Advantages of UUIDs:
- Distributed Systems: Generate IDs independently across multiple servers without coordination or collision risk.
- Offline Generation: Create valid IDs before database insertion, useful for offline-first applications.
- Merging Data: Combine databases from different sources without ID conflicts.
- Security: Non-sequential IDs prevent enumeration attacks (users can't guess other IDs).
- Microservices: Each service can generate its own IDs without central coordination.
- No Single Point of Failure: No need for a central ID generation service.
Trade-offs to Consider:
- Storage Size: UUIDs are 16 bytes (128 bits) vs 4-8 bytes for integers. This increases database size, especially for indexed columns.
- Index Performance: Random UUIDs (v4) can fragment B-tree indexes, potentially slowing inserts. Use v1 or sequential UUIDs if insert performance is critical.
- Readability: UUIDs like
550e8400-e29b-41d4-a716-446655440000are harder to read and debug than simple integers. - URL Length: UUIDs make URLs longer. Consider base64 encoding to shorten them if needed.
Database Integration Examples
PostgreSQL
-- Create table with UUID primary key
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- Insert with specific UUID
INSERT INTO users (id, email)
VALUES ('550e8400-e29b-41d4-a716-446655440000', 'user@example.com');
MySQL 8.0+
-- Create table with UUID
CREATE TABLE users (
id BINARY(16) PRIMARY KEY,
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert UUID (convert from string)
INSERT INTO users (id, email)
VALUES (UUID_TO_BIN('550e8400-e29b-41d4-a716-446655440000'), 'user@example.com');
MongoDB
// MongoDB uses its own ObjectId by default, but you can use UUIDs
db.users.insertOne({
_id: UUID("550e8400-e29b-41d4-a716-446655440000"),
email: "user@example.com",
createdAt: new Date()
});
Common Use Cases
- API Keys: Generate unique tokens for API authentication. Non-guessable and globally unique.
- Request/Transaction IDs: Track requests across distributed systems. Helpful for debugging and tracing.
- File Upload Naming: Prevent filename collisions when multiple users upload files with the same name.
- Session Tokens: Create secure, unique session identifiers for web applications.
- Message Queue IDs: Uniquely identify messages in queuing systems like RabbitMQ or Kafka.
- Distributed Event IDs: Track events across microservices without central coordination.
- Test Data Generation: Create unique identifiers for test records that won't conflict with production data.
- Cache Keys: Generate unique cache keys that won't collide across different services.
Best Practices
- Use v4 for Most Cases: Random UUIDs are simple, secure, and work for 99% of use cases.
- Store as Binary: In databases, store UUIDs as 16-byte binary rather than 36-character strings to save space (60% smaller).
- Index Wisely: If using v4 UUIDs as primary keys, consider clustering indexes or using sequential UUIDs (like PostgreSQL's
gen_random_uuid()) for better insert performance. - URL Encoding: For URLs, consider base64 encoding UUIDs to shorten them:
VQ6EAOKbQdSnFkRmVUQAAA==vs550e8400-e29b-41d4-a716-446655440000. - Lowercase vs Uppercase: Stick to lowercase for consistency. Most databases and systems treat UUIDs case-insensitively, but lowercase is the RFC standard.
- Validation: Always validate UUID format before using them, especially if accepting user input.
- Don't Parse for Information: Treat UUIDs as opaque identifiers. Don't try to extract timestamp or other information (even from v1).
Performance Considerations
Storage Impact
UUIDs take up more space than traditional IDs:
- As String: 36 bytes (with hyphens) or 32 bytes (without hyphens)
- As Binary: 16 bytes (most efficient)
- Integer ID: 4 bytes (INT) or 8 bytes (BIGINT)
Example: A table with 10 million rows using UUID primary keys will consume ~160 MB more storage than using BIGINT (16 bytes vs 8 bytes per row).
Index Performance
Random v4 UUIDs can cause index fragmentation because new values don't append to the end of the B-tree like sequential IDs do. This can slow down inserts on tables with millions of rows.
Solutions:
- Use sequential UUIDs (v1 or database-generated)
- Use hash indexes instead of B-tree indexes where supported
- Accept the trade-off if inserts aren't your bottleneck
Comparison Performance
UUID comparisons are slightly slower than integer comparisons, but the difference is negligible in most applications (nanoseconds per comparison).
Troubleshooting
Common Issues
- UUID Format Rejected: Ensure you're using the correct format with hyphens:
550e8400-e29b-41d4-a716-446655440000. Some systems accept without hyphens, others require them. - Case Sensitivity: Some databases treat UUIDs as case-sensitive strings. Always use lowercase to avoid mismatches.
- Version Mismatch: If a system expects v1 (time-based) UUIDs but you're generating v4 (random), it might reject them or behave unexpectedly.
- Storage Type Errors: If storing as binary, ensure you're converting properly. Storing string representation in binary column will corrupt the data.
- URL Encoding Issues: Hyphens in UUIDs don't need URL encoding, but if you're base64 encoding UUIDs, remember to use URL-safe base64 (replacing +/ with -_).
- Duplicate Generation: If you're seeing duplicates, verify you're actually generating new UUIDs and not reusing a variable. True UUID collisions are astronomically rare.
Validation
To verify a UUID is valid, check:
- Correct length: 36 characters with hyphens or 32 without
- Valid hex characters: 0-9, a-f (or A-F)
- Correct hyphen positions: 8-4-4-4-12 pattern
- Version digit: 13th character should indicate version (usually '4' for v4)
Frequently Asked Questions
Can two UUIDs ever collide?
Theoretically yes, but practically no. The collision probability for v4 UUIDs is approximately 1 in 2^122 (5.3 ร 10^36). You'd need to generate 2.71 quintillion UUIDs to have a 50% chance of a single collision. For comparison, there are only about 10^24 stars in the observable universe.
Which UUID version should I use?
Use v4 (random) for most applicationsโit's simple, secure, and unpredictable. Use v1 (time-based) only if you need sortable UUIDs or want to extract timestamp information. Use v5 (SHA-1 hash) if you need deterministic UUIDs that are reproducible from the same input.
Are UUIDs safe to use in URLs?
Yes, UUIDs are safe in URLs without encoding. They contain only hex digits (0-9, a-f) and hyphens, all of which are URL-safe characters. However, UUIDs make URLs longer. Consider shortening them with base64 encoding if URL length is a concern.
How do I generate UUIDs offline?
This tool works entirely in your browser using JavaScript's crypto.randomUUID() or equivalent random number generation. It requires no internet connection. You can also use command-line tools like uuidgen on Linux/Mac or libraries in your programming language.
What's the difference between UUID and GUID?
They're essentially the same thing. GUID (Globally Unique Identifier) is Microsoft's term for UUID. Microsoft's GUID format stores bytes in a slightly different order internally, but the string representation is identical. The terms are interchangeable in most contexts.
Can I use UUIDs as database primary keys?
Yes, and it's a common practice, especially in distributed systems. Benefits include offline generation, no coordination needed between services, and preventing ID enumeration attacks. Trade-offs include larger index sizes and potential insert performance impact with random v4 UUIDs. Store them as binary (16 bytes) rather than strings (36 bytes) for better performance.
How big are UUIDs in storage?
UUIDs are 128 bits (16 bytes) when stored in their native binary format. As strings with hyphens, they're 36 bytes. For maximum efficiency, always store UUIDs as binary in databases. For 1 million rows, this saves 20 MB per UUID column compared to string storage.
Are UUIDs sequential or random?
Depends on the version. Version 4 UUIDs (what this tool generates) are completely random and not sequential. Version 1 UUIDs are time-based and roughly sequential, making them sortable by creation time. Version 6 and 7 (newer specifications) are explicitly designed to be sequential.
Can I extract information from a UUID?
From v4 (random) UUIDs: No, they're purely random. From v1 (time-based) UUIDs: Yes, you can extract the timestamp and MAC address, but you shouldn't rely on this for application logic. Treat all UUIDs as opaque identifiers. If you need embedded information, use a different ID strategy.
How do UUIDs compare in speed to integer IDs?
UUID comparisons and joins are slightly slower than integers due to their larger size (16 bytes vs 4-8 bytes). In most applications, this difference is negligible (measured in nanoseconds). The performance impact on indexes can be more significant, especially with random v4 UUIDs causing B-tree fragmentation on large tables with heavy inserts.
Practical Guide
Use this checklist to get reliable results from UUID Generator and avoid common errors.
Input Checklist
- Decide length or format constraints before generating.
- Generate multiple candidates and keep the best fit.
- Store generated values securely if they are sensitive.
How to Get Better Results
- Start with a representative sample in UUID Generator and validate one test run first.
- Set generation constraints first (length, format, policy), then generate output.
- Create multiple candidates and keep only the values that satisfy downstream validation.
- Store generated values securely if they are used in credentials or production configs.
Expected Output Checklist
- Ready-to-use values in common formats with predictable structure.
- Fast re-generation options when constraints or requirements change.
- Copy-ready output that reduces manual formatting overhead.
Privacy and Data Handling
Generated output is created locally and is not stored by the site.