UUID versions — which one should you use
UUIDs come in several versions, each generated differently. Version 1 is based on the current timestamp and MAC address. This guarantees uniqueness but leaks the generating machine's MAC address, which is a privacy concern. Version 4 is randomly generated using a cryptographically secure random number generator. It's the most commonly used version for general-purpose identifiers.
Version 5 generates a deterministic UUID by hashing a namespace UUID and a name using SHA1. The same namespace and name always produce the same UUID, which is useful for generating consistent IDs from known input. Version 7 (a newer addition) is time-ordered, which improves database index performance — sequential UUIDs reduce B-tree fragmentation compared to random UUIDs.
For most applications — assigning IDs to new records, generating tokens, or identifying resources — UUID v4 is the right choice. If database insert performance at scale is a concern, consider UUID v7.
- UUID v1: timestamp + MAC address — unique but leaks device info
- UUID v4: cryptographically random — the standard choice
- UUID v5: deterministic hash from namespace + name
- UUID v7: time-ordered random — better for database indexes
What a UUID looks like
A UUID is written as five groups of hexadecimal digits separated by hyphens: 8-4-4-4-12 characters. For example: 6ba7b810-9dad-11d1-80b4-00c04fd430c8. The total is 32 hex characters = 128 bits.
In databases, UUIDs can be stored as a 36-character string or as a 16-byte binary value (more efficient). PostgreSQL has a native uuid type. MySQL/MariaDB store them as CHAR(36) or BINARY(16). Most ORMs handle this transparently.
UUIDs are case-insensitive — lowercase and uppercase hex characters are equivalent. By convention, UUIDs are usually written in lowercase.
Generating UUIDs in code and online
The Irreva UUID Generator creates v4 UUIDs using the browser's crypto.randomUUID() API, which is part of the Web Crypto API and uses a cryptographically secure random source. You can generate one at a time or in bulk.
In JavaScript/Node.js: crypto.randomUUID() (built-in Node 14.17+) or the uuid npm package. In Python: import uuid; str(uuid.uuid4()). In Java: UUID.randomUUID().toString(). In Go: google/uuid or github.com/gofrs/uuid.
For testing and development, having a handful of pre-generated UUIDs is useful for hardcoding in fixtures, seeds, and test cases. The bulk generator on Irreva lets you generate dozens at once.
