Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Converting UUIDs to bytes with uuid

parse and stringify convert between the text form of a UUID and its 16 raw bytes, for binary storage or protocols.

All uuid examples uuid: usage and stats

Converting UUIDs to bytes with uuid: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. String to bytes. parse(id) returns a Uint8Array of 16 values. The example prints them as decimals and as hex pairs, which line up with the hex in the string. [1]
  2. Bytes back to a string. stringify(bytes) gives back the original UUID. A second argument picks the offset to start reading from. [1]
  3. Write into a buffer. Passing a buffer and offset to v4 writes the bytes there instead of returning a string. Two UUIDs share one 32-byte array and stringify(buffer, 16) reads the second. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import { parse, stringify, v4 } from 'uuid'

const id = '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'

// String -> 16 bytes
const bytes = parse(id)
console.log('uuid:      ', id)
console.log('type:      ', bytes.constructor.name, 'of length', bytes.length)
console.log('bytes:     ', Array.from(bytes).join(', '))
console.log('hex pairs: ', Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join(' '))

// Bytes -> string
console.log('stringify: ', stringify(bytes))

// Write two UUIDs into one 32-byte buffer, then read each by offset
const buffer = new Uint8Array(32)
v4(undefined, buffer, 0)
v4(undefined, buffer, 16)
console.log('buffer[0..15]: ', stringify(buffer, 0))
console.log('buffer[16..31]:', stringify(buffer, 16))

// parse() throws on invalid input
try {
  parse('not-a-uuid')
} catch (err) {
  console.log('parse("not-a-uuid") throws:', err.name)
}
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Change the id string and compare its hex pairs with the bytes line. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with uuid 14.0.3. Needs WebGL.

More uuid examples

Random UUIDs with uuid v4 Time-based UUIDs with uuid v7 Name-based UUIDs with uuid v5 Validating UUIDs with uuid

Sources

  1. uuid README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with uuid? Ask AgentGid →