Last updated
Twitter Snowflake Examples — Real IDs and Decoded Timestamps
This page provides concrete examples of Twitter Snowflake IDs with their decoded timestamps. Real examples make the abstract algorithm tangible and give you a foundation for working with Twitter IDs in your own projects.
Example IDs and Their Decoded Dates
- ID
1529877576591609861→ May 2022 - ID
1700000000000000000→ reference milestone - ID
1800000000000000000→ reference milestone - ID
1900000000000000000→ reference milestone - ID
2024288437327843509→ recent example
Step-by-Step Decode of a Real ID
// Decode ID 1529877576591609861 step by step
const id = 1529877576591609861n;
// Step 1: Right-shift by 22 bits to get the raw timestamp
const rawTimestamp = id >> 22n;
console.log("Raw timestamp:", rawTimestamp.toString());
// This is milliseconds since Twitter's epoch
// Step 2: Add Twitter's epoch offset
const TWITTER_EPOCH = 1288834974657n;
const timestampMs = rawTimestamp + TWITTER_EPOCH;
console.log("Unix timestamp (ms):", timestampMs.toString());
// Step 3: Convert to a Date object
const date = new Date(Number(timestampMs));
console.log("Date:", date.toISOString());
// Output: 2022-05-26T...
Decoding All Components
// Full component extraction for ID 1529877576591609861
const id = 1529877576591609861n;
const TWITTER_EPOCH = 1288834974657n;
const timestamp = (id >> 22n) + TWITTER_EPOCH;
const datacenter = (id >> 17n) & 0x1Fn;
const worker = (id >> 12n) & 0x1Fn;
const sequence = id & 0xFFFn;
console.log("Date: ", new Date(Number(timestamp)).toISOString());
console.log("Datacenter: ", Number(datacenter));
console.log("Worker: ", Number(worker));
console.log("Sequence: ", Number(sequence));
Python Examples
# Decode multiple example IDs in Python
from datetime import datetime, timezone
TWITTER_EPOCH_MS = 1288834974657
example_ids = [
("1529877576591609861", "May 2022 tweet"),
("1700000000000000000", "Round number milestone"),
("1800000000000000000", "Round number milestone"),
("1900000000000000000", "Round number milestone"),
]
print(f"{'ID':<25} {'Description':<30} {'Decoded Date'}")
print("-" * 80)
for id_str, description in example_ids:
id_val = int(id_str)
ts_ms = (id_val >> 22) + TWITTER_EPOCH_MS
dt = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)
print(f"{id_str:<25} {description:<30} {dt.strftime('%Y-%m-%d %H:%M:%S UTC')}")
Binary Representation Example
// Show the binary structure of a Snowflake ID
function showBinaryStructure(idStr) {
const id = BigInt(idStr);
const binary = id.toString(2).padStart(64, "0");
console.log(`ID: ${idStr}`);
console.log(`Binary (64 bits):`);
console.log(binary);
console.log("");
console.log("Breakdown:");
console.log(` [63-22] Timestamp (41 bits): ${binary.slice(0, 41)}`);
console.log(` [21-17] Datacenter (5 bits): ${binary.slice(41, 46)}`);
console.log(` [16-12] Worker (5 bits): ${binary.slice(46, 51)}`);
console.log(` [11-0] Sequence (12 bits): ${binary.slice(51, 64)}`);
}
showBinaryStructure("1529877576591609861");
ID Growth Over Time
// Show how Twitter IDs have grown over time
const milestones = [
{ id: "1000000000000000000", label: "1.0 quintillion" },
{ id: "1500000000000000000", label: "1.5 quintillion" },
{ id: "1700000000000000000", label: "1.7 quintillion" },
{ id: "1800000000000000000", label: "1.8 quintillion" },
{ id: "1900000000000000000", label: "1.9 quintillion" },
{ id: "2000000000000000000", label: "2.0 quintillion" },
];
const TWITTER_EPOCH = 1288834974657n;
milestones.forEach(({ id, label }) => {
const bigId = BigInt(id);
const tsMs = (bigId >> 22n) + TWITTER_EPOCH;
const date = new Date(Number(tsMs));
console.log(`${label}: ${date.toDateString()}`);
});
Common Pitfalls
// Pitfall 1: Using regular numbers instead of BigInt
const id = 1529877576591609861; // WRONG — precision loss
console.log(id); // May print a different number
const id = 1529877576591609861n; // CORRECT — BigInt
console.log(id.toString()); // "1529877576591609861"
// Pitfall 2: JSON parsing loses precision
const json = '{"id": 1529877576591609861}'; // WRONG
const data = JSON.parse(json);
console.log(data.id); // Imprecise number
const json = '{"id_str": "1529877576591609861"}'; // CORRECT
const data = JSON.parse(json);
const id = BigInt(data.id_str); // Safe
// Pitfall 3: Forgetting the epoch offset
const rawTs = BigInt("1529877576591609861") >> 22n;
// rawTs is milliseconds since Twitter's epoch, NOT Unix epoch
// Must add TWITTER_EPOCH to get Unix timestamp
Java Example
// Java — decode a Twitter Snowflake ID
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class SnowflakeExample {
private static final long TWITTER_EPOCH_MS = 1288834974657L;
public static ZonedDateTime decode(long id) {
long timestampMs = (id >> 22) + TWITTER_EPOCH_MS;
return ZonedDateTime.ofInstant(
Instant.ofEpochMilli(timestampMs),
ZoneOffset.UTC
);
}
public static void main(String[] args) {
// Note: Java long can hold this value safely
long id = 1529877576591609861L;
ZonedDateTime date = decode(id);
System.out.println("Decoded date: " + date);
// Component breakdown
System.out.println("Datacenter: " + ((id >> 17) & 0x1F));
System.out.println("Worker: " + ((id >> 12) & 0x1F));
System.out.println("Sequence: " + (id & 0xFFF));
}
}
Snowflake ID Facts
- Twitter introduced Snowflake IDs in November 2010
- Pre-2010 Twitter IDs are sequential integers without embedded timestamps
- Both tweet IDs and user IDs use the same Snowflake format
- IDs are monotonically increasing — higher ID = created later
- The same ID always decodes to the same timestamp (deterministic)
- Snowflake IDs will remain valid until approximately year 2079
These examples provide a solid foundation for working with Twitter Snowflake IDs. The decoding algorithm is simple and consistent — once you understand it with these examples, you can apply it to any Twitter ID.