How to Generate UUIDs (v4 and v7)
UUIDs (Universally Unique Identifiers) are 128-bit identifiers used everywhere in software — database keys, API identifiers, session tokens, distributed systems. This guide shows you how to generate them and when to use v4 vs v7.
When You Need a UUID
- Creating unique identifiers for database records
- Generating correlation IDs for distributed systems
- Creating test data with realistic IDs
- Assigning unique keys to resources in an API
- Generating session or transaction identifiers
How to Generate UUIDs
Step 1: Open the tool
Go to the UUID Generator. A UUID is generated automatically.
Step 2: Choose version and format
Select v4 (random) or v7 (time-sortable). Choose lowercase, UPPERCASE, or no-hyphens format. Set the count for batch generation (up to 100).
Step 3: Copy
Click "Copy" for individual UUIDs or "Copy all" for the batch. Click "Regenerate" for new values.
v4 vs v7
UUID v4 — Random
122 bits of random data. No ordering, no timestamp. Use when you just need a unique ID and don't care about sort order.
UUID v7 — Time-sortable
First 48 bits encode the Unix timestamp in milliseconds. UUIDs generated later are lexicographically greater. Use for database primary keys — they maintain B-tree index efficiency unlike random v4.
Tips
- For database primary keys, prefer UUID v7 — it prevents index fragmentation that random v4 causes in B-tree indexes.
- Use no-hyphens format if you need to store UUIDs in systems that don't accept special characters.
- Need secure passwords instead? Use the Password Generator.
FAQ
What is the difference between UUID v4 and v7?
UUID v4 is purely random (122 random bits). UUID v7 encodes the current Unix timestamp in the first 48 bits, making UUIDs sortable by creation time. Use v4 for general unique IDs, v7 for database primary keys where chronological ordering matters.
Are these UUIDs unique enough?
Yes. UUID v4 has 122 random bits, giving 5.3 x 10^36 possible values. The probability of collision is astronomically low — you'd need to generate 1 billion UUIDs per second for 85 years to have a 50% chance of a single collision.
Can I use UUIDs as database primary keys?
Yes — UUID v7 is specifically designed for this. Its time-ordered nature prevents the B-tree fragmentation that random v4 UUIDs cause in database indexes. If you use v4 as a primary key, consider adding a separate auto-increment column for ordering.
Is the generation secure?
Yes. Both versions use the WebCrypto API's crypto.getRandomValues() for the random portion, which is a cryptographically secure pseudorandom number generator (CSPRNG).
Try It Now
Ready to generate? Open the UUID Generator — it works entirely in your browser with no sign-up required.