[ACCEPTED]-Why are there dashes in a .NET GUID?-uuid

Accepted answer
Score: 65

Technically, there are no "dashes" in 8 a GUID. A GUID is a 128-bit value which is 7 usually stored in the following manner (using 6 C# here to represent the structure):

public struct Guid
  public ulong Data1;
  public ushort Data2;
  public ushort Data3;
  public fixed byte Data4[8];

The 5 dashes are in the string representation of a GUID.

The dashes 4 are optional and are not required in a string 3 representation of a GUID.

That said, there are historical reasons as to where the placement of the dashes are, related 2 to how the GUIDs were generated, but that 1 historical semantic no longer applies.

Score: 44

In the initial version of the UUID (Universally 28 Unique Identifier) specification, each of 27 the data elements had a semantic meaning:

{ time_low } – { time_mid } – { time_high_and_version } – { clock_seq_and_reserved clock_seq_low } – { node_id }

These 26 elements were designed to provide temporal 25 (time bits), and spatial (host bits) uniqueness.

Version History

As 24 the the mathematical probability of collisions 23 in a keyspace of 2^1024 random bits was 22 found to be astronomically improbable, subsequent 21 versions of the UUID spec have phased out 20 the time and host data for security and 19 privacy reasons.

The only elements that retain 18 any meaning are the version bits and the 17 reserved bits.

Version 3 UUIDs are derived 16 from an MD5 hash of a URI or other Distinguished 15 Name.

Version 4 is generated with random 14 data and is, currently, the most common 13 implementation you'll see in the wild.

Version 12 5 is derived from a SHA1 hash.

Storage formats

Since the 11 hyphens are specified for the ASCII formatting 10 of UUIDs in the RFC, even though the individual 9 sections no longer retain their original 8 meaning, they are still required if you 7 need interoperability.

UUIDs are also sometimes 6 stored as a base64 or ascii85 encoded string 5 to save space for transmission over transports 4 that are not binary-safe, and adherence 3 to the RFC is not required.

Ascii:   3F2504E0-4F89-11D3-9A0C-0305E82C3301
Base64:  7QDBkvCA1+B9K/U0vrQx1A
Ascii85: 5:$Hj:Pf\4RLB9%kU\Lj

RFC4122 (see 2 page 3 specifically for the ABNF description 1 of the UUID format)
Wikipedia GUID UUID

Score: 14

You can get your guid in various formats.

Assuming 1 you're using c#:

Guid guid = Guid.NewGuid();









Score: 13

Hyphens denote the byte structure of a Guid.

typedef struct _GUID 
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   BYTE Data4[8];



You 5 can probably strip them before saving. At 4 least in .NET the constructor of the Guid 3 type will initialize a Guid variable from 2 its string representation regardless of 1 whether the hyphens are still there or removed.

Score: 9

It's just a convenience.



Score: 6

This is an example of chunking, just like 1 phone numbers, credit card numbers, etc.

Here is a good Wikipedia article about it.

Score: 4

Just about every visual represenation of 2 a guid that I've seen uses the dashed format. It's 1 much easier on the eyes.

Score: 3

The Guid class of .NET recognizes a bunch of 3 different formats: dashes as separators, no 2 separators, brackets as delimiters, parenthesis 1 as delimiters, no delimiters, etc

Score: 2

The hyphens are used to separate each number


Hex digits  Description
8           Data1
4           Data2
4           Data3
4           Initial two bytes from Data4
12          Remaining six bytes from Data4


Score: 1

That's just for convenience. GUID consists 5 of 16 bytes which makes up 32 characters 4 in hex text representation. Without hyphens 3 GUIDs are harder to perceive by humans and 2 harder to be recognized as GUIDs and not 1 some random nature 16-byte numbers.

Score: 0

If you want to store a guid somewhere, then 4 store it as an array of 16 bytes, not as 3 its textual representation. You will save 2 a lot of space, and the question of hyphens 1 will not arise.

Score: 0

The GUID is really just a number. The hyphens 5 show you how the various components are 4 broken down but aren't really part of the 3 number. It's like an IP address - you can 2 store a 32-bit number, or you can store 1 a string with dots in it, they are equivalent.

Score: 0

The hypens have avsolutely no effect on 5 the uniqueness or randomness of the value. They 4 are merely a holdover from the definition 3 of a GUID and visually separate the four 2 distinct parts of data that make up the 1 GUID.

More Related questions