What is GUID?

GUID (Globally Unique Identifier) is Microsoft's implementation of the UUID standard, a 128-bit identifier used to uniquely identify information in computer systems. GUIDs and UUIDs are essentially the same thing with different names.

Quick Facts

Full NameGlobally Unique Identifier
Created1990s by Microsoft (based on UUID standard)
SpecificationOfficial Specification

How It Works

GUID (Globally Unique Identifier) is Microsoft's term for UUID (Universally Unique Identifier). They are functionally identical 128-bit identifiers following the same RFC 4122 specification. The term GUID is primarily used in Microsoft ecosystems (.NET, Windows, SQL Server), while UUID is used in most other contexts. GUID is the term used primarily in Microsoft technologies (Windows, .NET, COM, SQL Server), while UUID is the standard term used elsewhere. Both follow the same format: 32 hexadecimal digits displayed as 8-4-4-4-12. GUIDs are generated using algorithms that ensure uniqueness without requiring a central authority. In .NET, the Guid struct provides methods for creating and manipulating GUIDs. SQL Server has the uniqueidentifier data type for storing GUIDs.

Key Characteristics

  • 128-bit identifier, same as UUID
  • Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • Microsoft terminology for UUID
  • Used extensively in Windows and .NET
  • COM components identified by GUIDs (CLSID, IID)
  • SQL Server uniqueidentifier type

Common Use Cases

  1. COM component identification (CLSID)
  2. Windows Registry keys
  3. .NET application identifiers
  4. SQL Server primary keys
  5. Active Directory object identifiers

Example

loading...
Loading code...

Frequently Asked Questions

What is the difference between GUID and UUID?

GUID and UUID are functionally identical 128-bit identifiers following the same RFC 4122 specification. GUID (Globally Unique Identifier) is the term used by Microsoft in Windows and .NET environments, while UUID (Universally Unique Identifier) is the standard term used in most other platforms and specifications.

Can two GUIDs ever be the same?

While theoretically possible, the probability of generating duplicate GUIDs is astronomically low. With 2^128 possible combinations, you would need to generate about 2.7 quintillion GUIDs before having a 50% chance of a collision. For practical purposes, GUIDs are considered unique.

How do I generate a GUID in C# or .NET?

In C#, use Guid.NewGuid() to generate a new GUID. For example: Guid myGuid = Guid.NewGuid(); This creates a version 4 (random) GUID. You can convert it to string using ToString() with optional format specifiers like 'N' (no hyphens), 'D' (standard format), 'B' (braces), or 'P' (parentheses).

Should I use GUID as a primary key in databases?

GUIDs as primary keys have pros and cons. They enable distributed ID generation without coordination and improve security by being unpredictable. However, they're larger than integers (16 bytes vs 4-8 bytes), can cause index fragmentation, and are harder to debug. Consider sequential GUIDs or alternative approaches for high-performance scenarios.

What is the format of a GUID?

A GUID consists of 32 hexadecimal characters displayed in the format 8-4-4-4-12, like: 3f2504e0-4f89-11d3-9a0c-0305e82c3301. The standard representation includes hyphens, though GUIDs can also be stored without hyphens or enclosed in braces depending on the context.

Related Tools

Related Terms

Related Articles