Skip to content

GUID Generator

Generate GUIDs for C#, .NET, SQL Server and Windows in any of the five .NET formats (D, N, B, P, X), upper or lower case, as random v4 or time-ordered v7. Paste an existing GUID to reformat it or see its .NET byte order.

Generated in your browser with crypto.getRandomValues()

    GUID and UUID: Same 128-bit Format

    GUID (globally unique identifier) is Microsoft's name for a UUID (universally unique identifier). Both are 128-bit values written as 32 hexadecimal digits, and a GUID made by Guid.NewGuid() is a standard random version 4 UUID. The differences are in how Microsoft software formats, stores and sorts them, which is what this page covers. For the structure of random UUIDs and the odds of a duplicate, see the random UUID generator.

    The Five .NET Formats: D, N, B, P and X

    Guid.ToString() takes a one-letter format. All five describe the same value, and Guid.Parse accepts any of them.

    The five .NET GUID string formats with the same example value
    FormatExampleUsed in
    D (default)00112233-4455-6677-8899-aabbccddeeffMost APIs, JSON, config files, SQL literals
    B{00112233-4455-6677-8899-AABBCCDDEEFF}Windows registry CLSIDs, Visual Studio projects, MSI
    N00112233445566778899aabbccddeeffFile names, URLs, compact storage
    P(00112233-4455-6677-8899-aabbccddeeff)Rare; some older COM tools
    X{0x00112233,0x4455,0x6677,{0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff}}C/C++ source code (GUID struct initializer)

    Creating GUIDs in C#, PowerShell and SQL Server

    C#

    Guid id = Guid.NewGuid();          // random, version 4
    Guid v7 = Guid.CreateVersion7();   // time-ordered, .NET 9+
    string s = id.ToString("B").ToUpperInvariant();
    bool ok = Guid.TryParse(input, out Guid parsed);

    PowerShell

    New-Guid                               # PowerShell 5+
    [guid]::NewGuid().ToString("N")

    SQL Server (T-SQL)

    SELECT NEWID();   -- random uniqueidentifier
    CREATE TABLE Orders (
      Id uniqueidentifier NOT NULL DEFAULT NEWSEQUENTIALID() PRIMARY KEY
    );

    Guid.Empty is all zeros (00000000-0000-0000-0000-000000000000). A field showing that value usually means the GUID was never set, not that it was generated.

    Worked Example: Why the Bytes Look Scrambled

    You store 00112233-4455-6677-8899-aabbccddeeff from C# as a 16-byte binary column, then look at the raw hex in a database tool or a network capture. It doesn't match. Why?

    Step 1: The text form, read left to right

    00 11 22 33 · 44 55 · 66 77 · 88 99 · aa bb cc dd ee ff

    Step 2: What Guid.ToByteArray() writes

    33 22 11 00 · 55 44 · 77 66 · 88 99 · aa bb cc dd ee ff

    Step 3: Spot the pattern

    Groups 1–3 are reversed (little-endian); the last 8 bytes are unchanged

    The GUID is the same; .NET stores the first three fields in little-endian order, a holdover from the Windows GUID struct. Other languages (Java, Python, PostgreSQL) use big-endian order, so the same bytes can come back as a different GUID if one side swaps and the other doesn't. In .NET 8 and later, ToByteArray(bigEndian: true) writes RFC order. The inspector below shows both orders for any GUID.

    GUID Primary Keys and Sort Order in SQL Server

    Random v4 GUIDs make poor clustered primary keys: each insert lands at a random point in the index, causing page splits and fragmentation. Two fixes exist, and they behave differently:

    • NEWSEQUENTIALID() generates GUIDs that increase on one machine until it restarts. It can only be used as a column default.
    • Version 7 GUIDs start with a timestamp, so they sort by creation time as text and in PostgreSQL, MySQL binary columns and .NET's own Guid.CompareTo.

    The catch: SQL Server's uniqueidentifier compares the last six bytes first. A v7 GUID's timestamp is at the start, so v7 values stored as uniqueidentifier do not sort by time in SQL Server. If you need time order there, use NEWSEQUENTIALID, or keep a separate indexed datetime or integer column.

    When a GUID Must Be Uppercase

    .NET writes GUIDs in lowercase, and RFC 9562 recommends lowercase output while accepting either case on input, so most systems don't care. The main exception is Windows Installer: the ProductCode, PackageCode and component GUIDs in an MSI must be uppercase, in braces. Lowercase GUIDs there produce validation errors or broken upgrades. The Windows registry and Visual Studio's Create GUID tool also show uppercase B format, so matching that style makes values easy to search for.

    Set the generator above to B and UPPERCASE for installer and registry work.

    Inspect or Reformat an Existing GUID

    Paste a GUID in any of the five formats to convert it to the others, check its version and variant, read the creation time from a v7 GUID, or compare its RFC and .NET byte orders. Nothing is sent anywhere; it all runs in your browser.

    Details of the pasted GUID
    PropertyValue
    Version6
    VariantRFC 9562 (standard)
    Format D00112233-4455-6677-8899-aabbccddeeff
    Format B{00112233-4455-6677-8899-aabbccddeeff}
    Format N00112233445566778899aabbccddeeff
    Format P(00112233-4455-6677-8899-aabbccddeeff)
    Format X{0x00112233,0x4455,0x6677,{0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff}}
    Bytes, RFC order00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
    Bytes, .NET ToByteArray()33 22 11 00 55 44 77 66 88 99 aa bb cc dd ee ff

    Frequently asked questions

    Is a GUID the same as a UUID?

    Yes. GUID is the Microsoft name. Guid.NewGuid() returns a standard version 4 UUID, and any UUID can be stored in a .NET Guid or SQL Server uniqueidentifier.

    How do I make an uppercase GUID with braces?

    Choose format B and UPPERCASE above, or in C# use Guid.NewGuid().ToString("B").ToUpperInvariant().

    Should I use NEWID() or NEWSEQUENTIALID()?

    NEWSEQUENTIALID() for a clustered primary key default, to avoid index fragmentation. NEWID() where the value must not be guessable from the previous one.

    Can I use a GUID as a password or secret token?

    Not as a substitute for a purpose-built token. A v4 GUID has 122 random bits, but v7 and sequential GUIDs are partly predictable, and GUIDs are often logged and shown in URLs.

    Sources