UnixTimestamp.app

What Is a GUID and How Is It Different From a UUID?

A GUID (globally unique identifier) is a 128-bit ID, and it is the same thing RFC 9562 calls a UUID. Here is how to read the GUID format and why byte order sometimes makes the same GUID look like two different values.

Jay HoldenPublished ยท 8 min read
Two identical five-part identifier tags, one wrapped in curly braces, showing that a GUID and a UUID are the same value
Key takeaways The short version, before the details.
  1. GUID is the name Microsoft uses for a UUID. Both are 128 bits and use the same text layout, so GUID vs UUID is a question of naming, not format.
  2. The GUID format is 32 hex digits grouped 8-4-4-4-12. You will also see it in braces, with a urn:uuid: prefix, in uppercase, or with the dashes removed.
  3. The one real difference is binary: Windows stores the first three fields little-endian. That can flip bytes between platforms, and it is why SQL Server sorts GUIDs in an odd order.
  4. The 13th hex digit gives the version. Versions 1, 6 and 7 contain a timestamp. Versions 3, 4 and 5 do not.

What is a GUID (globally unique identifier)?

A GUID is a 128-bit number that software creates when it needs an ID nobody else will ever produce, and it can do this without asking a central server. Windows uses GUIDs to name COM classes, interfaces, drivers and registry keys. .NET gives you one with Guid.NewGuid(), and SQL Server stores them in the uniqueidentifier column type.

You rarely see a GUID as a raw number. It is normally written as 32 hexadecimal digits in five groups, like this:

7c9e6679-7425-40de-944b-e07fc1f90ae7

Uniqueness comes from the way the value is built. Most modern GUIDs are version 4, which means 122 of the 128 bits are random. With that many possible values, two independently generated GUIDs are practically never the same.

GUID vs UUID: is there any difference?

In practice there is none. UUID (universally unique identifier) is the name used in the standard, first RFC 4122 and now RFC 9562. GUID is the name Microsoft used for the same idea when it adopted it for COM in the 1990s. A GUID that Guid.NewGuid() produces today is a standard version 4 UUID with the standard variant bits.

Here is what really differs between the two names:

  • Vocabulary. Windows and .NET documentation says GUID. Linux, Java, Python, PostgreSQL and most web APIs say UUID.
  • Display habits. Windows tools often show GUIDs in uppercase and inside curly braces. RFC 9562 asks for lowercase output.
  • Binary layout. The Windows GUID struct stores its first three fields in the machine's native byte order, which is little-endian on x86 and ARM. The RFC defines a single big-endian byte order. This is the only difference that can break code, and it has its own section below.

RFC 9562 also defines a Microsoft variant (the 17th hex digit is c or d) for backward compatibility with old COM GUIDs. You will rarely meet it. Nearly every GUID created today uses the standard variant, where that digit is 8, 9, a or b.

GUID format: the 8-4-4-4-12 layout

In text, a GUID is 32 hex digits split into groups of 8, 4, 4, 4 and 12 characters, with four hyphens between them, for 36 characters in total. The Windows GUID struct names the parts Data1, Data2, Data3 and Data4. Data4 is 8 bytes and covers the last two groups.

7c9e6679Data1, 4 bytes
7425Data2, 2 bytes
40deData3, version digit first
944bData4 start, variant digit first
e07fc1f90ae7Data4 rest, 6 bytes

The value stays the same no matter how you write it. You will run into these forms:

FormExampleWhere you see it
Canonical7c9e6679-7425-40de-944b-e07fc1f90ae7RFC 9562, APIs, PostgreSQL, .NET default output
Braced (registry format){7C9E6679-7425-40DE-944B-E07FC1F90AE7}Windows registry, COM class IDs, project and solution files
URNurn:uuid:7c9e6679-7425-40de-944b-e07fc1f90ae7XML, SOAP and other places that want a URI
Dashless7c9e667974254 0de944be07fc1f90ae7Legacy systems storing CHAR(32), file names, URLs

Why GUIDs have curly braces around them

The braces are a Windows convention and are not part of the value. The registry and COM have always written GUIDs as {...}, and in .NET you get that form with ToString("B"). The "N" format gives you the 32-digit dashless form, and "D" gives the plain hyphenated form. You can strip the braces before storing a GUID or comparing it with a UUID from another system.

Why Windows tools show GUIDs in uppercase

The registry and many Windows tools print uppercase hex. RFC 9562 says to output lowercase and to treat input as case-insensitive. So 7C9E6679-... and 7c9e6679-... are the same GUID. If you compare GUIDs as plain strings, normalise the case first, or compare the parsed values instead.

Paste a GUID in any formBraced, dashless or urn:uuid: input all decode the same way Open decoder

Why the same GUID bytes can show as two different strings

The text form is only half the story. When a GUID is stored as 16 raw bytes, the Windows GUID struct keeps Data1 (a 32-bit integer), Data2 and Data3 (16-bit integers) in little-endian order. The last 8 bytes stay in the order they are written. The RFC stores all 16 bytes big-endian, which is the same order as the text.

Take 00112233-4455-6677-8899-aabbccddeeff. .NET's Guid.ToByteArray returns 33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff. Suppose a Java, Python or PostgreSQL program reads those bytes as a standard UUID. It will print 33221100-5544-7766-8899-aabbccddeeff, which looks like a different ID.

import uuid

u = uuid.UUID("00112233-4455-6677-8899-aabbccddeeff")
print(u.bytes.hex())     # 00112233445566778899aabbccddeeff  (RFC order)
print(u.bytes_le.hex())  # 33221100554477668899aabbccddeeff  (Windows GUID order)

# Windows bytes read back as if they were RFC order:
print(uuid.UUID(bytes=u.bytes_le))  # 33221100-5544-7766-8899-aabbccddeeff

# The correct way to read Windows GUID bytes:
print(uuid.UUID(bytes_le=u.bytes_le))  # 00112233-4455-6677-8899-aabbccddeeff
var g = Guid.Parse("00112233-4455-6677-8899-aabbccddeeff");
Console.WriteLine(BitConverter.ToString(g.ToByteArray()));
// 33-22-11-00-55-44-77-66-88-99-AA-BB-CC-DD-EE-FF

Notice that the last two groups did not move. If a GUID you are debugging has a correct tail but a scrambled start, suspect byte order. The same applies to BINARY(16) columns filled by a .NET client and then read by something else. To fix it, choose one byte order at the boundary and convert there.

Why SQL Server sorts uniqueidentifier values in a strange order

SQL Server does not compare a uniqueidentifier from left to right. It treats the last group of 6 bytes as the most significant part. After that it compares the 4th group, then the 3rd, then the 2nd, and the first group last. Sorted with ORDER BY, the column looks scrambled because the part you read first counts least.

Here is an example of that order:

-- ascending ORDER BY on a uniqueidentifier column
ffffffff-ffff-ffff-ffff-000000000001
00000000-0000-0000-0000-000000000002

This matters when you want GUIDs that sort by creation time. A UUID v7 puts its timestamp in the first 48 bits. SQL Server gives those bits the least weight, so v7 values stored in uniqueidentifier do not come out in time order there. SQL Server's own NEWSEQUENTIALID() is designed around its comparison order. On PostgreSQL or in a BINARY(16) column that compares bytes left to right, v7 sorts the way you would expect.

How to tell which version a GUID is

Look at the 13th hex character, the first digit of the third group. In 7c9e6679-7425-<strong>4</strong>0de-944b-e07fc1f90ae7 it is 4, so this is a random version 4 GUID. The 17th character (the first digit of the fourth group) gives the variant. For standard GUIDs it is 8, 9, a or b.

Which GUID versions contain a timestamp

VersionHow it is builtTimestamp inside?
1Time in 100 ns steps since 15 October 1582, plus clock sequence and node (often a MAC address)Yes
3MD5 hash of a namespace and a nameNo
4122 random bitsNo
5SHA-1 hash of a namespace and a nameNo
6Same time source as v1, with the fields reordered so values sort by timeYes
7Unix time in milliseconds in the first 48 bits, then random bitsYes

A version 1 GUID can give away when it was created and, in older implementations, the MAC address of the machine that created it. That is one reason Windows moved to random v4 GUIDs. If you want an ID that sorts by time, compare v7 with the alternatives in our ULID vs UUID guide.

You do not have to count characters yourself. The UUID decoder takes a GUID with or without braces, dashes or the urn:uuid: prefix. It reports the version and variant and returns the canonical, braced, URN, hex and integer forms. For v1, v6 and v7 it also shows the embedded timestamp as a Unix time, a local date, ISO 8601 and a relative time. For v1 and v6 it adds the clock sequence and node.

Frequently asked questions

GUID stands for globally unique identifier. Microsoft uses the term for a 128-bit value that identifies something, such as a COM class, a database row or a device, with no central authority handing out numbers. Outside the Windows world the same value is called a UUID, short for universally unique identifier.

Yes. Both are 128 bits and use the same 8-4-4-4-12 hex text format, and GUIDs made today are standard RFC 9562 UUIDs, usually version 4. The only practical difference is binary storage. Windows keeps the first three fields little-endian, so raw bytes can come out reordered when they move between platforms.

The braces are a Windows display convention, not part of the value. The registry, COM and project files write GUIDs as {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}, and .NET produces that form with ToString("B"). You can remove the braces safely. The 32 hex digits inside are the whole identifier.

In theory, yes. In practice, not for random ones. A version 4 GUID has 122 random bits, so you would need about 2.7 quintillion of them before the chance of a single duplicate reached 50 percent. Real duplicates almost always come from bugs, such as a badly seeded random generator or a copied value.

Only some versions do. Versions 1 and 6 store time in 100-nanosecond steps since 15 October 1582, and version 7 stores Unix time in milliseconds. Versions 3, 4 and 5 are hashes or random bits and carry no time. The 13th hex character tells you which version you have.

SQL Server gives the last group of six bytes the most weight, then works back through the earlier groups, and compares the first group last. Values therefore look shuffled when sorted. It also means time-ordered UUID v7 values do not sort by time in a uniqueidentifier column, while NEWSEQUENTIALID() values do.