DevBlacksmith

Tech blog and developer tools

UUID v4 Generator

What Is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit label used to uniquely identify information in computer systems. The format was originally created by Apollo Computer and later standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE) in the early 1990s. It was formally defined in RFC 4122 in 2005.

A UUID v4 is generated using random or pseudo-random numbers. The probability of generating two identical UUIDs is astronomically low: you would need to generate 1 billion UUIDs per second for about 85 years to have a 50% chance of a single collision. That is roughly 2.71 quintillion UUIDs.

Fun fact: Microsoft calls them GUIDs (Globally Unique Identifiers) and they have been part of Windows since 1996. Every COM object, registry entry, and ActiveX control has one. The Linux kernel also uses UUIDs extensively for disk partition identification.

UUID Versions

There are 5 UUID versions. V1 uses timestamp + MAC address, V3 uses MD5 hashing, V4 is fully random (most popular), V5 uses SHA-1 hashing, and the newer V7 combines timestamp with randomness for better database indexing.

Database Primary Keys

UUIDs are popular as database primary keys because they can be generated without coordinating with a central server, which is perfect for distributed systems. PostgreSQL even has a native UUID type that takes only 16 bytes of storage.

The 4 and the Variant

In a UUID v4 like "550e8400-e29b-41d4-a716-446655440000", the "4" in the third group always indicates version 4, and the first digit of the fourth group is always 8, 9, a, or b (the variant bits).

Real-World Usage

UUIDs power more than you think: Bluetooth device pairing, Android app installation tracking, Minecraft player identification, USB device identification, and even the way your browser identifies extensions internally.