What is the string length of a GUID?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The standard string representation of a GUID (Globally Unique Identifier) is 36 characters long: 32 hexadecimal digits plus 4 hyphens, formatted as xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. However, the exact length depends on which format you use. Without hyphens it is 32 characters, with braces it is 38, and as a Base64 string it is 22-24 characters. Knowing these lengths matters for database column sizing, API validation, and input parsing.
GUID Structure and Format
A GUID is a 128-bit value. It is the same thing as a UUID (Universally Unique Identifier) defined by RFC 4122. The terms are used interchangeably, though "GUID" is more common in Microsoft ecosystems and "UUID" in Linux, Java, and web contexts.
The 128 bits are divided into five groups when displayed as a string:
The math:
Each hexadecimal digit represents 4 bits, so 32 hex digits = 128 bits.
All Standard String Formats and Their Lengths
Different platforms and APIs use different string representations. Here is every common format with its exact length.
| Format Name | Example | Length | Used By |
| Standard (D format) | 550e8400-e29b-41d4-a716-446655440000 | 36 | Most APIs, databases, RFC 4122 |
| No hyphens (N format) | 550e8400e29b41d4a716446655440000 | 32 | Compact storage, URLs |
| Braces (B format) | {550e8400-e29b-41d4-a716-446655440000} | 38 | Windows Registry, COM |
| Parentheses (P format) | (550e8400-e29b-41d4-a716-446655440000) | 38 | Rare, some legacy systems |
| Hex (X format) | {0x550e8400,0xe29b,0x41d4,{0xa7,0x16,...}} | Variable | C/C++ struct initialization |
| URN | urn:uuid:550e8400-e29b-41d4-a716-446655440000 | 45 | XML, SOAP, URN namespaces |
| Base64 | VQ6EAOKbQdSnFkRmVUQAAA== | 24 | Compact binary-safe encoding |
| Base64url (no padding) | VQ6EAOKbQdSnFkRmVUQAAA | 22 | JWT, URL-safe contexts |
The 36-character format (with hyphens, no braces) is by far the most common and is what most developers mean when they ask about GUID string length.
Generating GUIDs and Checking Length in Code
C# / .NET
Java
Python
JavaScript / TypeScript
SQL (PostgreSQL)
SQL (SQL Server)
Database Column Sizing
When storing GUIDs as strings (rather than native UUID types), use the correct column length.
| Database | Native Type | String Column Size |
| PostgreSQL | UUID (16 bytes) | CHAR(36) or VARCHAR(36) |
| MySQL | No native UUID type | CHAR(36) or BINARY(16) |
| SQL Server | UNIQUEIDENTIFIER (16 bytes) | CHAR(36) or NCHAR(36) |
| SQLite | No native UUID type | TEXT (no fixed size needed) |
Use CHAR(36) rather than VARCHAR(36) when every value is exactly 36 characters. Fixed-length columns avoid per-row length metadata and can be slightly faster for lookups. If your application might store both the 36-character and 32-character formats, use VARCHAR(36).
When the database supports a native UUID type (PostgreSQL, SQL Server), prefer it over string storage. Native types store 16 bytes instead of 36, saving disk space and improving index performance.
UUID Versions
The version number is encoded in the 13th character of the string (the M position in xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx). The string length is the same for all versions.
| Version | Generation Method | Example (13th char) |
| 1 | Timestamp + MAC address | 1 |
| 3 | MD5 hash of name + namespace | 3 |
| 4 | Random | 4 |
| 5 | SHA-1 hash of name + namespace | 5 |
| 7 | Unix timestamp + random (newer, sortable) | 7 |
Version 4 (random) is the most widely used. Version 7 is gaining adoption because its timestamp prefix makes UUIDs sortable, which improves database index performance compared to fully random Version 4 UUIDs.
Validation Regex
When accepting GUIDs as input, validate the format to prevent injection or malformed data.
Common Pitfalls
- Sizing a database column to 32 characters. The standard format is 36 characters (with hyphens). A
CHAR(32)column silently truncates the GUID and causes lookup failures. - Comparing GUIDs as case-sensitive strings. Hex digits
a-fandA-Fare equivalent.550e8400...and550E8400...represent the same GUID. Use case-insensitive comparison or normalize to lowercase before storing. - Assuming all GUID strings have hyphens. Some systems output the 32-character format without hyphens, or the 38-character format with braces. Parse defensively if you accept GUIDs from external sources.
- Storing GUIDs as strings when a native UUID column type is available. String storage uses 36 bytes minimum (plus encoding overhead) versus 16 bytes for a native type. On tables with millions of rows, this difference in index size is significant.
- Using Version 4 UUIDs as primary keys in B-tree indexes without considering insert performance. Random UUIDs scatter inserts across the index, causing page splits. Version 7 (timestamp-prefixed) UUIDs or ULID are better choices for ordered indexes.
- Confusing GUID byte order. Microsoft's GUID struct uses mixed-endian byte order (first three groups are little-endian, last two are big-endian). When converting between string and byte representations across platforms, byte order mismatches produce different GUIDs from the same string.
Summary
- The standard string length of a GUID is 36 characters (32 hex digits + 4 hyphens).
- Without hyphens: 32 characters. With braces: 38 characters. As Base64: 22-24 characters.
- Size database string columns as
CHAR(36)or use a nativeUUIDtype when available. - The underlying data is always 128 bits (16 bytes) regardless of string format.
- GUIDs and UUIDs are the same thing. Version 4 (random) is the most common; Version 7 (timestamp-sortable) is the modern recommendation for database primary keys.
- Validate format with a regex and compare case-insensitively when matching GUIDs as strings.
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.