Namespaced UUIDs

Version 3 (namespace w/ MD5) UUID:

Invalid Namespace UUID
Note: Per the RFC, "If backward compatibility is not an issue, SHA-1 Version 5 is preferred."

Version 5 (namespace w/ SHA-1) UUID:

Invalid Namespace UUID

Decode UUID

Generate Bulk

How many GUIDs do you want?:

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier that is unique across both space and time. It is commonly used in software development for various purposes, such as uniquely identifying entities.

How many versions of UUIDs are there and what are they used for?

There are five productive versions of UUIDs:

  • Version 1: Based on timestamp and MAC address.
  • Version 2: Similar to Version 1 with additional allocation for POSIX UID/GID.
  • Version 3 ( deprecated ): Uses a namespace and a user-defined name hashed with MD5.
  • Version 4: Generated randomly.
  • Version 5: Similar to Version 3 but uses SHA-1 hashing.
The Version 4 is the most used UUID version because the UUIDs are randomly generated.

How is a UUID structured?

A UUID is typically represented as 32 hexadecimal digits, displayed in five groups separated by hyphens: 550e8400-e29b-41d4-a716-446655440000xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx the UUI version can be identified by looking at the 13th digit (M) of the Hexadecimal UUID string. If then digit M is 1 then the UUID is version 1, if M is 3 then the UUID is version-3, etc.

There is also a “variant” and the 17th (N) digit represents it in hexadecimal:
BinaryHex DigitVariant
0xxx0 - 7reserved (NCS backward compatible)
10xx8 - bDCE 1.1, ISO/IEC 11578:1996
110xc - dreserved (Microsoft GUID)
1110ereserved (future use)
1111funknown / invalid. Must end with "0"

When to use UUID version 1?

UUID version 1 is generated based on the current timestamp and node (usually the MAC address). It's suitable for scenarios where time-based ordering is important, such as in distributed systems.

When to use UUID version 4?

UUID version 4 is generated using random or pseudo-random numbers. It's suitable for scenarios where uniqueness is more critical than time-based ordering.

What is a namespace in UUID version 3 and 5?

UUID versions 3 and 5 involve hashing a namespace identifier and a name to create a UUID. The namespace provides a way to avoid collisions between different sets of names.

Can UUIDs be predicted or duplicated?

The probability of generating the same UUID is extremely low, especially for version 4 UUIDs that use random numbers. However, it's not impossible, and precautions should be taken in critical applications. For instance, with UUID version 4, the chance of generating a duplicate is about 1 in 5.3x10^36.

How can I validate a UUID?

Valid UUIDs adhere to the specified format. You can use regular expressions or this app to validate a UUID and determine its Version.

Can UUIDs be used as security tokens?

While UUIDs are not designed for cryptographic security, they can be used as identifiers. For security-sensitive applications, additional measures such as encryption should be considered.

Is there a performance impact when using UUIDs as primary keys in databases?

While UUIDs may have a slightly higher storage overhead compared to sequential integers, modern databases are optimized to handle UUIDs efficiently. Considerations may vary based on the specific use case and database system.

What is the difference between UUID and GUID?

UUID (Universally Unique Identifier) and GUID (Globally Unique Identifier) are often used interchangeably. UUID is more commonly used in the context of open standards, while GUID is commonly associated with Microsoft technologies.

Can UUIDs be used as primary keys in databases?

Yes, UUIDs can be used as primary keys. They provide advantages in distributed systems and scenarios where uniqueness across systems is crucial. However, they are larger and can, in certain environments, be less efficient than traditional incremental IDs.

Can I use UUIDs in databases that do not support a native UUID type?

Yes, you can store UUIDs as strings or binary data in databases that do not have native UUID support. Be sure to use a consistent format and handle conversions appropriately.

How secure are UUIDs for sensitive data or cryptographic purposes?

While UUIDs are not intended for cryptographic security, they can be used as identifiers in secure systems. For cryptographic purposes, additional measures, such as proper key management, are recommended.

Are there any common problems or mistakes in using UUIDs?

Common mistakes include assuming UUIDs are ordered or time-based, using UUIDs as security tokens, and inefficient storage or indexing in databases.

How does a UUID version 1 timestamp work?

In UUID version 1, the timestamp is a 60-bit value representing the number of 100-nanosecond intervals since midnight, October 15, 1582 UTC. This is combined with clock sequence and node (MAC address) information.

Can I use UUIDs in URLs?

Yes, UUIDs can be used in URLs. Normally, UUIDs do not require special URL encoding as they consist of hexadecimal characters and hyphens, which are safe in URLs. UUIDs are not human-readable or memorable, which can be a downside in user-facing URLs. However, for machine-to-machine communication, this is not an issue.