Password Generator

UUID v5 Guide

How name-based UUID Version 5 works and where to use it

Skip straight to the UUID v5 generator or keep reading to understand name-based SHA-1 identifiers.

UUID v5 is a deterministic name-based UUID format. A namespace UUID and a name are combined, hashed with SHA-1, and converted into a valid UUID. That means the same namespace and name always produce the same UUID.

What is UUID v5?

UUID Version 5 is a name-based identifier defined in RFC 4122 and supported by RFC 9562. It is like UUID v3, but uses SHA-1 hashing instead of MD5, giving stronger collision resistance for the generated UUID.

550e8400-e29b-5d4c-8a2d-28aee8c68a55
└───────┘ └──┘ └───┘ └───────────────┘
 namespace  ver  hash   hash
             5      (SHA-1)

How UUID v5 is generated

  • Combine a namespace UUID and a name string into a byte sequence.
  • Compute SHA-1 over that combined data.
  • Set the UUID version bits to 0101 and variant bits to 10.
  • Format the result as a standard UUID string with hyphens.

When to use UUID v5

UUID v5 is ideal when you need deterministic UUIDs for the same logical entity, such as URLs, user IDs, or resource names. Since the UUID is derived from the namespace and name, it is repeatable while still avoiding collisions across namespaces.

Compared to UUID v3

UUID v3 uses MD5 hashing while UUID v5 uses SHA-1. SHA-1 offers stronger collision resistance, making v5 the preferred choice for new name-based UUID implementations.

Compared to UUID v4

UUID v4 is purely random with no logic or input-determinism. UUID v5 is fully deterministic: the same inputs always produce the same identifier. Choose v5 when you need repeatable derived IDs.

Code examples for UUID v5

uuid npm package

Use name-based UUID generation with SHA-1 in Node.js and browser JavaScript.

# Install
npm install uuid
import { v5 as uuidv5, DNS } from 'uuid';

const id = uuidv5('example.com', DNS);
console.log(id);

Python standard library

Use the built-in uuid module for UUID v5 generation.

import uuid

uid = uuid.uuid5(uuid.NAMESPACE_DNS, "example.com")
print(uid)

google/uuid

Generate deterministic UUID v5 values from a namespace and name.

# Install
go get github.com/google/uuid
package main

import (
    "fmt"
    "github.com/google/uuid"
)

func main() {
    id := uuid.NewSHA1(uuid.NameSpaceDNS, []byte("example.com"))
    fmt.Println(id)
}

UuidCreator

Use the UUID Creator library to create SHA-1 based UUID v5 values.

<!-- Maven dependency -->
<dependency>
  <groupId>com.github.f4b6a3</groupId>
  <artifactId>uuid-creator</artifactId>
  <version>4.0.1</version>
</dependency>
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.UUID;

UUID id = UuidCreator.getNameBasedSha1(UUID.fromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), "example.com");
System.out.println(id);

Manual SHA-1 helper

Create UUID v5 values in .NET without external dependencies.

using System;
using System.Security.Cryptography;
using System.Text;

static Guid CreateUuid5(Guid ns, string name) {
  var nsBytes = ns.ToByteArray();
  Array.Reverse(nsBytes);
  var nameBytes = Encoding.UTF8.GetBytes(name);
  var hashInput = new byte[nsBytes.Length + nameBytes.Length];
  Buffer.BlockCopy(nsBytes, 0, hashInput, 0, nsBytes.Length);
  Buffer.BlockCopy(nameBytes, 0, hashInput, nsBytes.Length, nameBytes.Length);

  using var sha1 = SHA1.Create();
  var hash = sha1.ComputeHash(hashInput);

  hash[6] = (byte)((hash[6] & 0x0F) | 0x50);
  hash[8] = (byte)((hash[8] & 0x3F) | 0x80);

  Array.Reverse(hash, 0, 4);
  Array.Reverse(hash, 4, 2);
  Array.Reverse(hash, 6, 2);

  var guidBytes = new byte[16];
  Array.Copy(hash, guidBytes, 16);
  return new Guid(guidBytes);
}

var id = CreateUuid5(Guid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"), "example.com");
Console.WriteLine(id);

ramsey/uuid

Generate UUID v5 values using Ramsey UUID's name-based API.

# Install
composer require ramsey/uuid
use Ramsey\Uuid\Uuid;

$id = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'example.com');
echo $id->toString();

uuidtools gem

Create UUID v5 values in Ruby using SHA-1 name-based generation.

# Install
gem install uuidtools
require 'uuidtools'

namespace = UUIDTools::UUID.parse('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
puts UUIDTools::UUID.sha1_create(namespace, 'example.com')

uuid crate

Use the Rust uuid crate to generate UUID v5 values from a namespace and name.

# Cargo.toml
[dependencies]
uuid = { version = "1", features = ["v5"] }
use uuid::Uuid;

fn main() {
    let id = Uuid::new_v5(&Uuid::NAMESPACE_DNS, b"example.com");
    println!("{}", id);
}

Elixir UUID package

Generate UUID v5 values in Elixir using a UUID library from Hex.

# mix.exs dependencies
{:elixir_uuid, "~> 1.2"}
UUID = Elixir.UUID

id = UUID.uuid5(:dns, "example.com")
IO.puts(id)

Erlang uuid library

Generate UUID v5 values in Erlang with a UUID dependency.

% rebar.config
{deps, [{uuid, "*"}]}
UUID = uuid:uuid5("6ba7b810-9dad-11d1-80b4-00c04fd430c8", "example.com").
io:format("~s~n", [UUID]).

PostgreSQL

UUID v5 values are typically generated in application code and stored as UUIDs in the database.

CREATE TABLE resources (
  id UUID PRIMARY KEY,
  name TEXT
);

-- Insert deterministic UUID v5 generated from code
INSERT INTO resources (id, name) VALUES ('5e4f4ee5-5f49-5d4c-84d0-beb21a9b1f09', 'example.com');

Frequently asked questions

Is UUID v5 deterministic?

Yes. UUID v5 always produces the same UUID for the same namespace and name input, making it ideal for deterministic identifier generation.

Should I use UUID v5 or UUID v3?

UUID v5 uses SHA-1 hashing, while v3 uses MD5. SHA-1 is generally preferred for stronger collision resistance, so choose v5 for new name-based UUIDs.

Can UUID v5 values collide?

Collisions are possible in theory, but extremely unlikely when you use different namespaces for distinct domains and a strong input name. UUID v5 is deterministic, not random.

Ready to generate? Open the UUID v5 generator →