UUID Generator - Create Version 1 and Version 4 UUIDs
Generate Version 1 (time-based) and Version 4 (random) UUIDs online. This free tool explains the UUID format, formula, and use cases for database keys and APIs.
UUID Generator
Documentation
UUID Generator
A UUID generator is a tool that creates a Universally Unique Identifier, or UUID: a 128-bit code used to label a piece of data so that no other item, anywhere, is likely to share the same label. This page generates Version 1 (time-based) and Version 4 (random) UUIDs.
What is a UUID?
A UUID is a 128-bit number written as 32 hexadecimal digits (the characters 0-9 and a-f). It is split into five groups separated by hyphens, in the pattern 8-4-4-4-12, for 36 characters in total. An example UUID looks like this:
1550e8400-e29b-41d4-a716-446655440000
2UUIDs are defined by RFC 4122, a standard published by the Internet Engineering Task Force in 2005. Software uses them to identify database rows, files, user sessions, and other records without needing a central authority to hand out numbers. Because the space of possible UUIDs is so large, two computers can generate UUIDs independently, at the same moment, and almost never produce the same one.
UUID format and structure
The 128 bits of a UUID are split into named fields. Each field takes up a fixed number of bits:
time_low- 32 bitstime_mid- 16 bitstime_hi_and_version- 16 bitsclock_seq_hi_and_reserved- 8 bitsclock_seq_low- 8 bitsnode- 48 bits
Four bits inside time_hi_and_version mark the UUID's version number (1 through 5), and two bits inside clock_seq_hi_and_reserved mark the variant, which tells software how to read the rest of the fields.
How to generate a UUID with this tool
- Pick a version: Version 1 (time-based) or Version 4 (random).
- Select "Generate." The tool builds a new 128-bit UUID immediately.
- Select "Copy" to copy the result to the clipboard.
- Paste the UUID into code, a database, or a configuration file.
Version 4 suits most jobs, including database keys and session tokens, because it carries no information about when or where it was made. Version 1 suits records that benefit from being sortable by creation time, such as log entries.
UUID version 1 vs version 4
Version 1 encodes the current timestamp, plus a randomly chosen clock sequence and node value. The RFC 4122 standard allows the node value to be a computer's real network (MAC) address, but it also allows a randomly generated node value as a privacy-preserving alternative. This tool always uses the random option: its Version 1 UUIDs never read or expose a real MAC address. Because the timestamp sits at the front of the ID, Version 1 UUIDs generated in order can be sorted by creation time.
Version 4 is built from random bits, with a few bits fixed to mark the version and variant. It carries no timestamp and no machine-specific data, so it reveals nothing about when or where it was created. It is not sortable by creation order.
Three other versions exist in the standard but are not generated by this tool: Version 2 (DCE Security, rarely used), Version 3 and Version 5 (built by hashing a namespace and a name with MD5 or SHA-1, so the same input always produces the same UUID).
How to calculate a UUID (formula)
Version 4:
- Generate 128 random bits.
- Set the four version bits, the first hex digit of the third group, to
0100(hex4). - Set the top two bits of the fourth group to
10(so the first hex digit of that group is8,9,a, orb).
Only 122 of the 128 bits are actually random, since 6 bits are fixed by steps 2 and 3. That gives 2^122, or about 5.3 × 10^36, possible Version 4 UUIDs.
Version 1:
- Take the current time as a count of 100-nanosecond intervals since October 15, 1582, the start date used by the Gregorian calendar reform. This fills the
time_low,time_mid, and part oftime_hi_and_version. - Generate a 14-bit clock sequence, used to avoid collisions if the system clock is set backward.
- Generate a 48-bit node value.
- Set the version bits to
0001and the variant bits to10.
Across all UUID versions, the full 128-bit space holds 2^128, or about 3.4 × 10^38, possible values. That count is so large that random collisions are not a practical concern.
Worked example
Take the example UUID from earlier: 550e8400-e29b-41d4-a716-446655440000.
- Third group,
41d4: the first digit is4, marking this as a Version 4 UUID. - Fourth group,
a716: the first digit,a(binary1010), starts with10, the required variant bits. - The remaining hex digits are the random payload.
A program reading this UUID checks the 4 and the 10 pattern to confirm the format, then treats the rest as an opaque random value.
Common uses for UUIDs
- Primary keys in databases, especially when multiple servers create records at the same time without checking in with each other.
- Session tokens and API keys, usually Version 4 for the privacy it provides.
- Identifiers for files, events, and resources in distributed systems such as microservices.
- Device IDs in large IoT networks, where each device can generate its own ID offline.
The main trade-off is size: a UUID takes 16 bytes of storage, compared with 4 or 8 bytes for a simple integer counter, and some databases index UUIDs more slowly than sequential integers.
Alternatives to UUIDs
Auto-incrementing integers are smaller and simpler but do not work well once more than one server needs to hand out IDs independently. Snowflake IDs, developed at Twitter, combine a timestamp with a worker ID to produce compact, sortable identifiers across a distributed system. ULIDs (Universally Unique Lexicographically Sortable Identifiers) are a newer format designed to be both random and sortable by creation time, unlike a standard Version 4 UUID.
History of the UUID standard
The UUID concept began in the 1980s at Apollo Computer, as part of its Network Computing System. The Open Software Foundation later adopted the format for its Distributed Computing Environment. The Internet Engineering Task Force published the current standard, RFC 4122, in 2005, and it remains the reference definition used across programming languages, databases, and cloud platforms today.
Frequently asked questions
What is a UUID generator used for? It creates unique identifiers for databases, distributed systems, session tokens, API keys, and device IDs, so that no two records need to share the same identifier.
What is the difference between UUID v1 and v4? Version 1 encodes a timestamp and can be sorted by creation time. Version 4 is fully random and carries no timestamp. This tool's Version 1 output uses a randomly generated node value rather than a real MAC address, so it does not expose machine-identifying information either.
Does Version 1 expose my MAC address? Not with this tool. RFC 4122 allows a Version 1 UUID's node field to hold a real MAC address, but this generator always fills that field with random bits instead.
Are UUIDs guaranteed to be unique? No identifier scheme can guarantee absolute uniqueness, but the 128-bit space holds about 3.4 × 10^38 possible values, and a Version 4 UUID has about 5.3 × 10^36 possible random values. The chance of a duplicate is small enough to ignore for almost any practical use.
Can I use a UUID as a database primary key? Yes. UUIDs work well as primary keys in distributed systems because any node can generate one without checking with a central server. The cost is 16 bytes of storage per key, more than a typical integer, and potentially slower index performance on very large tables.
Is a UUID the same as a GUID? Yes. GUID (Globally Unique Identifier) is Microsoft's name for the same concept defined by RFC 4122 as a UUID.
Can Version 4 UUIDs be sorted by creation time? No. Version 4 UUIDs are random, so their order carries no information about when they were created. Version 1 UUIDs, or alternatives like ULIDs, are needed for that.
References
- Leach, P., Mealling, M., & Salz, R. (2005). A Universally Unique IDentifier (UUID) URN Namespace. RFC 4122. https://tools.ietf.org/html/rfc4122
- Universally unique identifier. (2023). In Wikipedia. https://en.wikipedia.org/wiki/Universally_unique_identifier
- Snowflake ID. (2023). In Wikipedia. https://en.wikipedia.org/wiki/Snowflake_ID
- ULID Spec. (n.d.). GitHub. https://github.com/ulid/spec