Calculate Twitter Snowflake ID

SNOWFLAKE ID
📅 CREATION DATE
⏱️ UNIX TIMESTAMP
🕐 TIME AGO

Snowflake Components

Timestamp (bits 22-63):
Datacenter ID (bits 17-21):
Worker ID (bits 12-16):
Sequence (bits 0-11):

Last updated

What is a Twitter Snowflake Calculator?

A Twitter snowflake calculator is a tool that decodes Twitter's unique 64-bit snowflake IDs and extracts all embedded information including timestamps, datacenter IDs, worker IDs, and sequence numbers.

Twitter Snowflake Calculator — Examples

The Twitter Snowflake Calculator performs calculations with Twitter Snowflake IDs: converting IDs to timestamps, finding IDs for specific dates, calculating ID ranges for time periods, and analyzing Snowflake structure. Here are practical examples for all these operations.

ID to Timestamp

// JavaScript — decode Snowflake ID to timestamp
function snowflakeToTimestamp(idStr) {
  const id = BigInt(idStr);
  const twitterEpoch = 1288834974657n;
  const timestampMs = (id >> 22n) + twitterEpoch;
  
  return {
    ms: timestampMs.toString(),
    seconds: Math.floor(Number(timestampMs) / 1000),
    date: new Date(Number(timestampMs)).toISOString()
  };
}

console.log(snowflakeToTimestamp("1529877576591609861"));
// { ms: "1653572200000", seconds: 1653572200, date: "2022-05-26T..." }

Timestamp to ID Range

// JavaScript — find the ID range for a specific date
function dateToIdRange(date) {
  const twitterEpoch = 1288834974657n;
  const tsMs = BigInt(date.getTime()) - twitterEpoch;
  
  const minId = (tsMs << 22n).toString();
  const maxId = ((tsMs << 22n) | 0x3FFFFFn).toString();
  
  return { minId, maxId };
}

// Example: find IDs for January 1, 2023
const range = dateToIdRange(new Date("2023-01-01T00:00:00Z"));
console.log("Min ID:", range.minId);
console.log("Max ID:", range.maxId);
# Python — timestamp to ID range
from datetime import datetime, timezone

def date_to_id_range(dt):
    """Get the min and max Snowflake IDs for a given datetime."""
    twitter_epoch_ms = 1288834974657
    ts_ms = int(dt.timestamp() * 1000) - twitter_epoch_ms
    
    min_id = ts_ms << 22
    max_id = (ts_ms << 22) | 0x3FFFFF  # all lower 22 bits set
    
    return min_id, max_id

# Example
dt = datetime(2023, 1, 1, tzinfo=timezone.utc)
min_id, max_id = date_to_id_range(dt)
print(f"Min ID: {min_id}")
print(f"Max ID: {max_id}")

ID Range for a Time Period

# Python — get ID range for a date range (useful for API queries)
from datetime import datetime, timezone

def get_id_range_for_period(start_dt, end_dt):
    """
    Get the Snowflake ID range for a time period.
    Use since_id and max_id in Twitter API queries.
    """
    twitter_epoch_ms = 1288834974657
    
    start_ms = int(start_dt.timestamp() * 1000) - twitter_epoch_ms
    end_ms   = int(end_dt.timestamp() * 1000) - twitter_epoch_ms
    
    since_id = start_ms << 22
    max_id   = (end_ms << 22) | 0x3FFFFF
    
    return {
        "since_id": str(since_id),
        "max_id": str(max_id),
        "start": start_dt.isoformat(),
        "end": end_dt.isoformat()
    }

# Example: tweets from Q1 2023
start = datetime(2023, 1, 1, tzinfo=timezone.utc)
end   = datetime(2023, 3, 31, 23, 59, 59, tzinfo=timezone.utc)

range_info = get_id_range_for_period(start, end)
print(f"since_id: {range_info['since_id']}")
print(f"max_id:   {range_info['max_id']}")

Snowflake Structure Analyzer

// JavaScript — full Snowflake structure breakdown
function analyzeSnowflake(idStr) {
  const id = BigInt(idStr);
  const twitterEpoch = 1288834974657n;
  
  const timestampMs = (id >> 22n) + twitterEpoch;
  const datacenterId = Number((id >> 17n) & 0x1Fn);
  const workerId = Number((id >> 12n) & 0x1Fn);
  const sequence = Number(id & 0xFFFn);
  
  // Binary representation (padded to 64 bits)
  const binary = id.toString(2).padStart(64, "0");
  
  return {
    id: idStr,
    binary: {
      timestamp:  binary.slice(0, 41),
      datacenter: binary.slice(41, 46),
      worker:     binary.slice(46, 51),
      sequence:   binary.slice(51, 64)
    },
    decoded: {
      timestampMs: timestampMs.toString(),
      date: new Date(Number(timestampMs)).toISOString(),
      datacenterId,
      workerId,
      sequence
    }
  };
}

const analysis = analyzeSnowflake("1529877576591609861");
console.log(JSON.stringify(analysis, null, 2));

Calculate Days Between Two IDs

// JavaScript — calculate time difference between two Snowflake IDs
function timeBetweenIds(id1Str, id2Str) {
  const twitterEpoch = 1288834974657n;
  const id1 = BigInt(id1Str);
  const id2 = BigInt(id2Str);
  
  const ts1 = Number((id1 >> 22n) + twitterEpoch);
  const ts2 = Number((id2 >> 22n) + twitterEpoch);
  
  const diffMs = Math.abs(ts2 - ts1);
  
  return {
    milliseconds: diffMs,
    seconds: Math.floor(diffMs / 1000),
    minutes: Math.floor(diffMs / 60000),
    hours: Math.floor(diffMs / 3600000),
    days: (diffMs / 86400000).toFixed(2)
  };
}

const diff = timeBetweenIds("1700000000000000000", "1900000000000000000");
console.log(`Days between IDs: ${diff.days}`);

Using ID Ranges in Twitter API Queries

# Python — use calculated ID range in API query
import requests
from datetime import datetime, timezone

def fetch_tweets_for_period(query, start_dt, end_dt, bearer_token):
    twitter_epoch_ms = 1288834974657
    
    start_ms = int(start_dt.timestamp() * 1000) - twitter_epoch_ms
    end_ms   = int(end_dt.timestamp() * 1000) - twitter_epoch_ms
    
    since_id = str(start_ms << 22)
    max_id   = str((end_ms << 22) | 0x3FFFFF)
    
    headers = {"Authorization": f"Bearer {bearer_token}"}
    params = {
        "query": query,
        "since_id": since_id,
        "max_results": 100,
        "tweet.fields": "created_at,author_id,text"
    }
    
    response = requests.get(
        "https://api.twitter.com/2/tweets/search/recent",
        headers=headers,
        params=params
    )
    return response.json()

# Fetch tweets about Python from January 2023
start = datetime(2023, 1, 1, tzinfo=timezone.utc)
end   = datetime(2023, 1, 31, tzinfo=timezone.utc)
results = fetch_tweets_for_period("#python", start, end, "YOUR_TOKEN")

Snowflake Capacity Reference

The Snowflake Calculator handles all these operations in one place, making it the go-to tool for developers and researchers who work with Twitter data and need to navigate the ID-timestamp relationship efficiently.

Snowflake ID Structure

Twitter snowflake IDs are 64-bit integers with the following structure:

  • Bits 0-11 (12 bits): Sequence number (0-4095)
  • Bits 12-16 (5 bits): Worker ID (0-31)
  • Bits 17-21 (5 bits): Datacenter ID (0-31)
  • Bits 22-63 (42 bits): Timestamp in milliseconds since Twitter epoch

How to Use the Calculator

  • Enter any Twitter ID (tweet ID, user ID, DM ID, etc.)
  • Click "Calculate & Decode" to see all components
  • View the binary representation and decoded values
  • See the exact creation date and timestamp

Calculator Features

  • ✅ Decode all snowflake components
  • ✅ View binary representation
  • ✅ Extract timestamp and date
  • ✅ Show datacenter and worker IDs
  • ✅ Display sequence number
  • ✅ 100% accurate calculations

Frequently Asked Questions

Yes, our Twitter Snowflake Calculator is completely free with no registration required. Use it unlimited times without any restrictions.

Yes, all processing happens locally in your browser. Your data never leaves your device and is not stored on our servers.

No installation needed. The tool works directly in your web browser on any device.

Enter your input, click the action button, and get instant results. Copy the output for use in your projects.