Skip to main content

4. Specification

4.1. Format

The UUID format is 16 octets; some bits of the eight octet variant field specified below determine finer structure.

4.1.1. Variant

The variant field determines the layout of the UUID. That is, the interpretation of all other bits in the UUID depends on the setting of the bits in the variant field. The variant field consists of a variable number of the most significant bits of octet 8 of the UUID.

The following table lists the contents of the variant field, where the letter "x" indicates a "don't-care" value.

Msb0Msb1Msb2Description
0xxReserved, NCS backward compatibility
10xThe variant specified in this document
110Reserved, Microsoft Corporation backward compatibility
111Reserved for future definition

4.1.2. Layout and Byte Order

To minimize confusion about bit assignments within octets, the UUID record definition is defined only in terms of fields that are integral numbers of octets. The fields are presented with the most significant one first.

FieldData TypeOctet #Note
time_lowunsigned 32 bit integer0-3The low field of the timestamp
time_midunsigned 16 bit integer4-5The middle field of the timestamp
time_hi_and_versionunsigned 16 bit integer6-7The high field of the timestamp multiplexed with the version number
clock_seq_hi_and_reservedunsigned 8 bit integer8The high field of the clock sequence multiplexed with the variant
clock_seq_lowunsigned 8 bit integer9The low field of the clock sequence
nodeunsigned 48 bit integer10-15The spatially unique node identifier

UUID Structure (128 bits):

 0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| time_low |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| time_mid | time_hi_and_version |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|clk_seq_hi_res | clk_seq_low | node (0-1) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| node (2-5) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

4.1.3. Version

The version number is in the most significant 4 bits of the time stamp (bits 4 through 7 of the time_hi_and_version field).

The following table lists the currently-defined versions for this UUID variant:

Msb0-3VersionDescription
00011The time-based version specified in this document
00102DCE Security version, with embedded POSIX UIDs
00113The name-based version specified in this document that uses MD5 hashing
01004The randomly or pseudo-randomly generated version specified in this document
01015The name-based version specified in this document that uses SHA-1 hashing

4.1.4. Timestamp

The timestamp is a 60-bit value. For UUID version 1, this is represented by Coordinated Universal Time (UTC) as a count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar).

For UUID version 3 or 5, the timestamp is a 60-bit value constructed from a name as described in Section 4.3.

For UUID version 4, the timestamp is a randomly or pseudo-randomly generated 60-bit value, as described in Section 4.4.

4.1.5. Clock Sequence

For UUID version 1, the clock sequence is used to help avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.

The clock sequence MUST be originally (i.e., once in the lifetime of a system) initialized to a random number to minimize the correlation across systems.

For UUID version 3 or 5, the clock sequence is a 14-bit value constructed from a name as described in Section 4.3.

For UUID version 4, clock sequence is a randomly or pseudo-randomly generated 14-bit value.

4.1.6. Node

For UUID version 1, the node field consists of an IEEE 802 MAC address, usually the host address. For systems with multiple IEEE 802 addresses, any available one can be used.

For UUID version 3 or 5, the node field is a 48-bit value constructed from a name as described in Section 4.3.

For UUID version 4, the node field is a randomly or pseudo-randomly generated 48-bit value.

4.1.7. Nil UUID

The nil UUID is special form of UUID that is specified to have all 128 bits set to zero:

00000000-0000-0000-0000-000000000000

4.2. Algorithms for Creating a Time-Based UUID

4.2.1. Basic Algorithm

The basic algorithm for generating a time-based UUID:

  1. Obtain a system-wide global lock
  2. Read the current time
  3. Get the current node ID
  4. If the node ID has changed since the last UUID was generated, set the clock sequence to a random value
  5. If the current time is before the last timestamp, increment the clock sequence
  6. Save the timestamp and node ID
  7. Release the global lock
  8. Format the UUID using the timestamp, clock sequence, and node ID

4.2.2. Generation Details

Timestamp: The timestamp is a 60-bit value constructed from the system time. The timestamp resolution is 100 nanoseconds.

Clock Sequence: The clock sequence is initially set to a random value. It is incremented each time the clock moves backward or the node ID changes.

Node ID: The node ID is typically an IEEE 802 MAC address.

4.3. Algorithm for Creating a Name-Based UUID

The algorithm for creating a name-based UUID (version 3 or version 5):

  1. Allocate a UUID to use as a "name space ID" for all UUIDs generated from names in that name space
  2. Choose either MD5 (version 3) or SHA-1 (version 5) as the hash algorithm
  3. Convert the name to a canonical sequence of octets
  4. Compute the hash of the name space ID concatenated with the name
  5. Set octets zero through 15 to octets zero through fifteen of the hash
  6. Set the four most significant bits (bits 12 through 15) of octet 6 to the appropriate version number
  7. Set the two most significant bits (bits 6 and 7) of octet 8 to zero and one, respectively

4.4. Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers

The version 4 UUID is meant for generating UUIDs from truly random or pseudo-random numbers.

The algorithm is as follows:

  1. Set all the bits to randomly (or pseudo-randomly) chosen values
  2. Set the four most significant bits (bits 12 through 15) of octet 6 to the 4-bit version number (0100 binary)
  3. Set the two most significant bits (bits 6 and 7) of octet 8 to zero and one, respectively

4.5. Node IDs that Do Not Identify the Host

This section describes alternatives for generating node IDs that do not identify the host:

  1. Random Node ID: Set the least significant bit of the first octet of the node ID to one (multicast bit). This marks the UUID as not based on a real MAC address.

  2. Persistent Random Node ID: Generate a random node ID once and store it for reuse. This provides consistency across reboots while maintaining privacy.


Note: For detailed implementation examples and complete algorithms, please refer to the official RFC 4122 specification and Appendix A.