How to Generate GUIDs in C#

Generate GUIDs in C# with Guid.NewGuid() for random values and Guid.CreateVersion7() on .NET 9 or newer when you want timestamp ordering plus randomness.

Recommendation: use GUID v4 for general-purpose random IDs. Use GUID v7 when you want better insertion locality and time ordering in logs or databases.

How to generate GUID v4 in C#

The built-in Guid.NewGuid() API is the standard way to generate a random GUID in .NET.

using System;

Guid id = Guid.NewGuid();
Console.WriteLine(id);

// Example: d0c5d3e8-4a52-4a65-aada-2b9d88f0d4dc

How to generate GUID v7 in C#

.NET 9 and later can generate a time-ordered GUID directly with Guid.CreateVersion7(). If you target an older runtime, use a library that supports RFC 9562 v7.

using System;

Guid id = Guid.CreateVersion7();
Console.WriteLine(id);

// Example: 0195d9f7-f4f2-7c44-bdb3-6f5de9a1a6f0

Native support notes

  • C# and .NET natively expose GUID generation APIs instead of separate UUID terminology.
  • GUID v4 is widely available through Guid.NewGuid().
  • GUID v7 is built in on .NET 9 and later.
  • Other UUID versions are not first-class everyday APIs in the base library.

Practical notes

  • Use v4 when sort order does not matter.
  • Use v7 when you want more database-friendly ordering.
  • Do not confuse SQL Server uniqueidentifier storage with UUID version semantics.

Frequently Asked Questions

Yes. In .NET the native name is GUID, but the underlying 128-bit identifier format matches the UUID standards.

Guid.CreateVersion7() is available on .NET 9 and later. Use Guid.NewGuid() for random identifiers everywhere, and use a v7-capable library if you need time-ordered IDs on older runtimes.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.