Search code examples
guiduuid

Is there any difference between a GUID and a UUID?


I see these two acronyms being thrown around and I was wondering if there are any differences between a GUID and a UUID?


Solution

  • The simple answer is: no difference, they are the same thing.

    For most practical purposes, treat them as 16 byte (128 bits) values that are used as a unique identifier. In Microsoft-speak they are called GUIDs, but call them UUIDs when not using Microsoft-speak.

    Even the authors of the UUID specification and Microsoft claim they are synonyms:

    • From the introduction to IETF RFC 4122 "A Universally Unique IDentifier (UUID) URN Namespace": "a Uniform Resource Name namespace for UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDentifier)."

    • From the ITU-T Recommendation X.667, ISO/IEC 9834-8:2004 International Standard: "UUIDs are also known as Globally Unique Identifiers (GUIDs), but this term is not used in this Recommendation."

    • And Microsoft even claims a GUID is specified by the UUID RFC: "In Microsoft Windows programming and in Windows operating systems, a globally unique identifier (GUID), as specified in [RFC4122], is ... The term universally unique identifier (UUID) is sometimes used in Windows protocol specifications as a synonym for GUID."

    Detailed answer

    But the correct answer is "it depends". It depends on what the question means when it says "UUID"...

    The first part depends on what the asker is thinking when they are saying "UUID".

    Microsoft's claim implies that all UUIDs are GUIDs. But are all GUIDs real UUIDs? That is, is the set of all UUIDs just a proper subset of the set of all GUIDs, or is it the exact same set?

    Looking at the details of the RFC 4122, there are four different "variants" of UUIDs. This is mostly because such 16 byte identifiers were in use before those specifications were brought together in the creation of a UUID specification. From section 4.1.1 of RFC 4122, the four variants of UUID are:

    1. Reserved, Network Computing System backward compatibility
    2. The variant specified in RFC 4122 (of which there are five sub-variants, which are called "versions")
    3. Reserved, Microsoft Corporation backward compatibility
    4. Reserved for future definition.

    According to RFC 4122, all UUID variants are "real UUIDs", then all GUIDs are real UUIDs. To the literal question "is there any difference between GUID and UUID" the answer is definitely no for RFC 4122 UUIDs: no difference (but subject to the second part below).

    But not all GUIDs are variant 2 UUIDs (e.g. Microsoft COM has GUIDs which are variant 3 UUIDs). If the question was "is there any difference between GUID and variant 2 UUIDs", then the answer would be yes -- they can be different. Someone asking the question probably doesn't know about variants and they might be only thinking of variant 2 UUIDs when they say the word "UUID" (e.g. they vaguely know of the MAC address+time and the random number algorithms forms of UUID, which are both versions of variant 2). In which case, the answer is yes different.

    So the answer, in part, depends on what the person asking is thinking when they say the word "UUID". Do they mean variant 2 UUID (because that is the only variant they are aware of) or all UUIDs?

    The second part depends on which specification being used as the definition of UUID.

    If you think that was confusing, read the ITU-T X.667 ISO/IEC 9834-8:2004 which is supposed to be aligned and fully technically compatible with RFC 4122. It has an extra sentence in Clause 11.2 that says, "All UUIDs conforming to this Recommendation | International Standard shall have variant bits with bit 7 of octet 7 set to 1 and bit 6 of octet 7 set to 0". Which means that only variant 2 UUID conform to that Standard (those two bit values mean variant 2). If that is true, then not all GUIDs are conforming ITU-T/ISO/IEC UUIDs, because conformant ITU-T/ISO/IEC UUIDs can only be variant 2 values.

    Therefore, the real answer also depends on which specification of UUID the question is asking about. Assuming we are clearly talking about all UUIDs and not just variant 2 UUIDs: there is no difference between GUID and IETF's UUIDs, but yes difference between GUID and conforming ITU-T/ISO/IEC's UUIDs!

    Practical notes

    The information above does not go into the details of the UUID/GUID values, or how you get/generate them. But there are two misconceptions about the values that should be cleared up.

    1. Representation of UUID/GUIDs

    Firstly, the same UUID/GUID is a 16 bytes (128 bits) value that can be represented in different ways.

    In memory or storage, it can be represented compactly as binary data. For example, it can be represented as an array of sixteen bytes, eight 16-bit words, or four 32-bit integers; signed or unsigned. The endian is significant when using words or integers.

    In text or strings, it is commonly represented in hexadecimal with hyphens:

    hhhhhhhh-hhhh-Yhhh-Xhhh-hhhhhhhhhhhh
    

    where h, X and Y are hexadecimal characters.

    Some programs might only accept uppercase characters, or only lowercase characters---even though the case is not significant to the value of the UUID/GUID. Some programs might require the hyphens to be omitted or to be present only in those positions---even though the hyphens are not significant to the value of the UUID/GUID.

    The positions of the hyphens reflect the time-based version of UUIDs: separating the various time, clock and MAC address fields. Obviously, those fields don't have meaning when it comes to the other version of UUIDs. But, by convention, those positions of the hyphens are still used.

    2. Interpretation of the bytes

    Secondly, always use a library to generate a UUID/GUID. Generating 16 random bytes does not guarantee a valid UUID/GUID. Even when using a version 4 UUID, some of the bytes must have specific values.

    In the above hexadecimal string template, three bits of the hexadecimal character in position X encodes the UUID's variant. For the variant defined in RFC 4122, X will be either 8, 9, A or B.

    If the UUID is an RFC 4122 variant, the bits represented by the hexadecimal character in position Y encode its version. For example, 4 indicates a version 4.

    Randomly generating 16 bytes would not guarantee the bytes would have the correct values in those two fields.

    For the full details, see RFC 4122. But normally you don't need to know their internal structure. If you are just using values you have been given, just treat them as 16 byte (128 bits) values that are used as a unique identifier.