{
  "id": 12763023,
  "title": "I measured whether .NET Guid sorting is broken. It isn't.",
  "url": "https://urgent.news/2026/10/08/i-measured-whether-net-guid-sorting-is-broken-it-isnt",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-08T02:12:52.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/_4143d12ca219f32cb635/i-measured-whether-net-guid-sorting-is-broken-it-isnt-4o2"
  },
  "original_language": "en",
  "account": "A recent investigation sought to determine whether sorting .NET Guids is broken. As it turns out, the claim is incorrect, and the issue lies elsewhere. The key to resolving this matter lies in conducting a proper test that can distinguish between different hypotheses.\n\nTo begin, the investigator measured the CompareTo method of .NET Guids directly. It was found that Guid.CompareTo sorts in logical value order, disproving the initial claim. However, the real challenge was to create a sample that could differentiate between the two hypotheses: sorting by string order versus sorting by raw byte order.\n\nThe test required values that would demonstrate the disagreement between these two sorting methods. The ToByteArray() method was utilized to convert the Guid into bytes, with the first four bytes being displayed in both little-endian and big-endian formats. Through this process, it was revealed that .NET stores the first three groups of a Guid in little-endian internally.\n\nThe crucial finding was that sorting by string order and sorting by raw byte order yielded different results. When sorted by string, the values came out in one order, while sorting by raw bytes resulted in the exact reverse order. This highlighted the importance of distinguishing between the two hypotheses.\n\nThe third line of the investigation, which compared the CompareTo order with the raw byte order, proved to be the most significant. Without this comparison, it would be impossible to determine whether a passing test was actually due to the inability of the test to fail. Thus, it was established that .NET Guid.CompareTo is independent of the ToByteArray() layout.\n\nThe source of the confusion lies in the fact that the byte layout returned by ToByteArray() does not adhere to RFC 9562 network byte order. Instead, the first three groups of the Guid are reversed. This discrepancy becomes evident when comparing the first four bytes, with the reversed order of the first three groups clearly visible.\n\nMoving forward, it is essential to create a sample that can effectively differentiate between the two hypotheses. Python provides both the RFC order and the default layout of .NET Guids, labeling them as .bytes and .bytes_le, respectively. SQL Server utilizes a different ordering scheme, which contributes to the majority of \"sorting is weird\" stories.\n\nIn conclusion, sorting .NET Guids is not broken. The layout differences only become apparent when a Guid is serialized and read back using a different library. To avoid any confusion, it is recommended to explicitly specify the desired ordering when transmitting a Guid across system boundaries. The findings of this investigation were verified on .NET 10.0.400, with the same results obtained on .NET 10.0.11 from an earlier test conducted on 2026-09-14. For a comprehensive analysis, including the Python and SQL Server aspects, please refer to the full write-up available at https://uuid.withuse.io/uuid-vs-guid/.",
  "summary": "\" Guid sorting in .NET is weird\" is a claim you run into often enough that I wanted a number for it. So I measured CompareTo directly. It sorts in logical value order. The claim is wrong, and the thing people are actually hitting is something else. You need a sample that can tell the two hypotheses apart This is the part that took me two attempts. .NET stores the first three groups of a Guid in…",
  "key_points": [
    "Guid.CompareTo sorts in logical value order, disproving claim of broken sorting",
    "ToByteArray() reveals .NET stores first three Guid groups in little-endian",
    "CompareTo order differs from raw byte order, clarifying layout confusion"
  ],
  "editors_take": "The clarification on .NET Guid sorting resolves a common misconception, highlighting the importance of distinguishing between sorting by string order and raw byte order when working with Guids across different systems.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}