Last updated
Twitter / X Snowflake IDs
Twitter uses Snowflake IDs — 64-bit integers that encode a timestamp, worker ID, and sequence number. This means every tweet, user, and DM has an ID that contains the exact millisecond it was created. Decoding a tweet ID reveals when it was posted, which is useful for research, archiving, and timeline reconstruction.
Snowflake ID Structure
| Bits | Field | Description |
|---|---|---|
| 63–22 (42 bits) | Timestamp | Milliseconds since Twitter epoch (Nov 4, 2010) |
| 21–17 (5 bits) | Datacenter ID | 0–31 |
| 16–12 (5 bits) | Worker ID | 0–31 |
| 11–0 (12 bits) | Sequence | 0–4095 per millisecond per worker |
Decoding a Twitter Snowflake ID
// Twitter epoch: November 4, 2010 01:42:54 UTC
const TWITTER_EPOCH = 1288834974657n;
function decodeTwitterId(idStr) {
const id = BigInt(idStr);
// Extract timestamp (top 42 bits)
const timestamp = (id >> 22n) + TWITTER_EPOCH;
const date = new Date(Number(timestamp));
// Extract datacenter and worker IDs
const datacenterId = (id & 0x3E0000n) >> 17n;
const workerId = (id & 0x1F000n) >> 12n;
const sequence = id & 0xFFFn;
return {
id: idStr,
timestamp: Number(timestamp),
date: date.toISOString(),
datacenterId: Number(datacenterId),
workerId: Number(workerId),
sequence: Number(sequence)
};
}
// Example: decode tweet ID 1234567890123456789
console.log(decodeTwitterId('1234567890123456789'));