The Short Answer
UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier) are essentially the same thing. The difference is primarily in naming convention:
- UUID is the official term defined by RFC 4122 and used in most contexts
- GUID is Microsoft's term, commonly used in Windows and .NET environments
Both refer to 128-bit identifiers formatted as 32 hexadecimal digits, typically displayed in five groups separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
What is a UUID?
A UUID is a 128-bit number used to uniquely identify information in computer systems. The key properties are:
- Universally unique: The probability of generating duplicate UUIDs is astronomically low
- Decentralized generation: No central authority needed to ensure uniqueness
- Fixed size: Always 128 bits (16 bytes)
UUID Format
// Standard format (36 characters including hyphens)
550e8400-e29b-41d4-a716-446655440000
^ ^
| |
| Version (4 = random)
|
Time-low (8 hex digits)
The format breaks down as:
- 8-4-4-4-12 hexadecimal digits
- Total: 32 hex digits + 4 hyphens = 36 characters
- Binary: 128 bits = 16 bytes
UUID Versions
There are five defined versions of UUIDs, each with different generation methods:
Generated from timestamp and MAC address. Can reveal when and where it was created. Potential privacy concern.
Similar to v1 but includes POSIX UID/GID. Rarely used in practice.
Generated by hashing a namespace and name with MD5. Same input always produces same UUID.
Generated using random or pseudo-random numbers. Most widely used version due to simplicity and good uniqueness guarantees.
Like v3 but uses SHA-1 instead of MD5. Preferred over v3 when name-based UUIDs are needed.
Newer Versions (Draft)
RFC 4122 revision proposes additional versions:
- Version 6: Reordered time-based (sortable)
- Version 7: Unix timestamp-based (sortable, recommended for databases)
- Version 8: Custom/vendor-specific
When to Use UUIDs
Good Use Cases
- Distributed systems: Multiple servers can generate IDs without coordination
- Database primary keys: Especially for tables that might be merged or sharded
- API resources: Non-guessable identifiers for public-facing resources
- File naming: Guaranteed unique names for uploaded files
- Session tokens: Unpredictable identifiers for user sessions
- Message/event IDs: Tracking items through distributed systems
When to Consider Alternatives
- Auto-incrementing IDs: Better for simple, single-database applications where sequential ordering matters
- Snowflake IDs: When you need sortable, time-based IDs at Twitter-scale
- NanoID: When you need shorter, URL-safe identifiers
- ULID: When you need sortable, Crockford Base32 encoded identifiers
UUID Collision Probability
The chance of generating duplicate UUIDs is effectively zero for practical purposes. Some perspective:
- UUID v4 has 122 random bits (6 bits are fixed for version/variant)
- That's 5.3 x 10^36 possible values
- Generating 1 billion UUIDs per second would take about 100 years to have a 50% chance of a single collision
In practice, you're more likely to experience a hardware failure than a UUID collision.
Generating UUIDs in Different Languages
JavaScript
// Modern browsers (v4)
crypto.randomUUID();
// Node.js
const { randomUUID } = require('crypto');
randomUUID();
PHP
// Laravel
use Illuminate\Support\Str;
$uuid = Str::uuid();
// Native PHP 7+
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
random_int(0, 0xffff), random_int(0, 0xffff),
random_int(0, 0xffff),
random_int(0, 0x0fff) | 0x4000,
random_int(0, 0x3fff) | 0x8000,
random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
);
Python
import uuid # Version 4 (random) uuid.uuid4() # Version 1 (time-based) uuid.uuid1()
SQL
-- PostgreSQL SELECT gen_random_uuid(); -- MySQL 8+ SELECT UUID(); -- SQL Server SELECT NEWID();
Database Considerations
Storage
UUIDs can be stored in different ways:
- BINARY(16): Most efficient (16 bytes), requires conversion
- CHAR(36): Human-readable but uses more space
- UUID type: Native support in PostgreSQL and some other databases
Indexing
Random UUIDs (v4) can cause index fragmentation because they're not sequential. Solutions:
- Use UUID v7 (time-sorted) for better index performance
- Use ordered UUIDs that rearrange bytes for sequential storage
- Accept the trade-off if uniqueness/unpredictability is more important than index efficiency
Key Takeaways
- UUID and GUID are the same thing with different names
- UUID v4 (random) is the most commonly used version
- Use UUIDs when you need decentralized, unique identifiers
- The collision probability is negligible in practice
- Consider UUID v7 for database primary keys (sortable)
- Store as BINARY(16) for efficiency, or CHAR(36) for convenience
Generate UUIDs Instantly
Use our UUID generator to create v4 UUIDs right in your browser.
Open UUID Generator →