URN - UUIDs (Universally Unique IDentifier) or GUIDs (Globally Unique IDentifier)


UUID (Universally Unique IDentifier) are identifier

An UUID is also known as GUIDs (Globally Unique IDentifier) because they are guaranteed to be unique and avoid then collision.

A UUID is an identifier that is unique across both :

  • time (Every UUID has a timestamp)
  • space (where the uuid is generated)

Since UUIDs are unique and persistent, you can use them as URNs (The string representation of a UUID is fully compatible with the URN syntax. ) See the example for an URN example


  • version 1 with the urn prefix (the 1 in 11d0)
  • version 4 (the 4 in 4e2b)


  • A UUID can be used for multiple purposes, from tagging objects with an extremely short lifetime, to reliably identifying very persistent objects across a network
  • A UUID is generally used to uniquely identify some object or entity on the Internet.
  • For instance, Windows requires them when an installer install an application


  • Pro:
    • An UUID does not need an central authority to be created
    • A UUID is reasonably small. This lends itself well to sorting, ordering, and hashing of all sorts, storing in databases, simple allocation, and ease of programming in general.
  • Cons:
    • Since a UUID is a fixed size and contains a time field, it is possible for values to rollover (around A.D. 3400, depending on the specific algorithm used).


Three algorithms are used to generate UUIDs and be sure that they are unique:


UUID is a fixed size of 16 octets and contains a time field.

To guarantee uniqueness, it's using

  • a clock sequence to help avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.
  • a node field that consists of an IEEE 802 MAC address, usually the host address. (it will change if the network card is replaced)


The format of an UUID is in EBNF syntax for bit.

Because every application use them as URN, the bit sequence is generally converted as a string representation.

UUID = time-low "-" time-mid "-" time-high-and-version "-" clock-seq-and-reserved clock-seq-low "-" node

time-low               = 4hexOctet
time-mid               = 2hexOctet
time-high-and-version  = 2hexOctet
clock-seq-and-reserved = hexOctet
clock-seq-low          = hexOctet
node                   = 6hexOctet
hexOctet               = hexDigit hexDigit
hexDigit = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" /  "a" / "b" / "c" / "d" / "e" / "f" / "A" / "B" / "C" / "D" / "E" / "F"

Variant and version (Type)

The real version of a UUID is given by:

  • its variant field (a type) - The variant field contains a value which identifies the layout
  • and its version (a subtype) - The version field holds a value that describes the type


  • The variant field (type) consists of a variable number of the most significant bits of octet 8 of the UUID.
  • The version number (sub-type) is in the most significant 4 bits of the time stamp (bits 4 through 7 of the time_hi_and_version field). It has the following meaning
    • 1 - The time-based version
    • 2 - DCE Security version, with embedded POSIX UIDs.
    • 3 - The name-based version that uses MD5 hashing.
    • 4 - The randomly or pseudo-randomly generated
    • 5 - The name-based version that uses SHA-1 hashing.

Version 4 (Random)

The version 4 UUID is the most used and is meant for generating UUIDs from truly-random or pseudo-random numbers. ref doc

Because it's not device scoped, it provides better privacy properties.

The chance of collision are so small that it can be ignored.

Furthermore, Google Analytics use it to generate the Anonymous Id on the mobile platform.

  • the timestamp is a randomly or pseudo-randomly generated 60-bit value
  • clock sequence is a randomly or pseudo-randomly generated 14-bit value
  • the node field is a randomly or pseudo-randomly generated 48-bit



Javascript Code

From stackoverflow

function uuidv4() {
  return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
    (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)


Uuid package



<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/uuid.min.js" integrity="sha256-xd9tlwS9ralt8HcFIwWPOVGS7p0f4TiA6x1X3+ZBdTM=" crossorigin="anonymous"></script>

Windows SDK

The Windows SDK you get by installing Visual Studio also contains a GUID-generation tool, available, for example, at

%ProgramFiles%\Microsoft SDKs\Windows\v7.1A\Bin\uuidgen.exe
%ProgramFiles%\Windows Kits\8.1\bin\x86\uuidgen.exe

Documentation / Reference

Powered by ComboStrap