Convert Shortcode to ID

📌 Try these examples:
INSTAGRAM SHORTCODE
📊 MEDIA ID
📅 CREATION DATE
🔗 INSTAGRAM URL

Last updated

Instagram Shortcode to ID Converter

Convert Instagram shortcodes to numeric media IDs. Every Instagram post has both a shortcode (used in URLs) and a numeric ID (used in the API). This tool converts between them instantly.

How to Get Instagram Shortcodes

From Instagram URLs:

instagram.com/p/CxOWiQNphlr/

The shortcode is the alphanumeric string between /p/ and the trailing slash.

From Reel URLs:

instagram.com/reel/CxOWiQNphlr/

Reels use the same shortcode format as regular posts.

When to Use Each Format

Enter any Instagram shortcode or numeric ID to instantly convert between the two formats.

What is Instagram Shortcode?

Instagram shortcodes are base64-encoded identifiers that represent numeric media IDs. They're shorter and more URL-friendly than the full numeric IDs, making them perfect for sharing links.

Code Examples

JavaScript
// JavaScript - Instagram Shortcode to ID
function shortcodeToMediaId(shortcode) {
  const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
  let mediaId = 0n;
  
  for (let i = 0; i < shortcode.length; i++) {
    const char = shortcode[i];
    const index = alphabet.indexOf(char);
    if (index === -1) throw new Error('Invalid shortcode');
    mediaId = mediaId * 64n + BigInt(index);
  }
  
  return mediaId.toString();
}

// Example usage
const mediaId = shortcodeToMediaId('CxOWiQNphlr');
console.log(mediaId); // 2792188468659568875

// Extract timestamp (Instagram uses Twitter's epoch)
const INSTAGRAM_EPOCH = 1288834974657n;
const timestamp = Number((BigInt(mediaId) >> 22n) + INSTAGRAM_EPOCH);
console.log(new Date(timestamp)); // Post creation date
Python
# Python - Instagram Shortcode to ID
def shortcode_to_media_id(shortcode):
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
    media_id = 0
    
    for char in shortcode:
        index = alphabet.index(char)
        media_id = media_id * 64 + index
    
    return media_id

# Example usage
media_id = shortcode_to_media_id('CxOWiQNphlr')
print(media_id)  # 2792188468659568875

# Extract timestamp
from datetime import datetime
INSTAGRAM_EPOCH = 1288834974657
timestamp = ((media_id >> 22) + INSTAGRAM_EPOCH) / 1000
print(datetime.fromtimestamp(timestamp))  # Post creation date

Use Cases

Instagram Shortcode Format

Character Set: A-Z, a-z, 0-9, - (dash), _ (underscore)

Length: Typically 11 characters

Encoding: Base64 variant (URL-safe)

Case Sensitive: Yes - 'A' and 'a' are different

Frequently Asked Questions

Q: Can I convert media ID back to shortcode?

A: Yes! The conversion is reversible. Use our Instagram ID to Shortcode converter for the reverse operation.

Q: Do reels have different shortcodes?

A: No, Instagram reels use the same shortcode format as regular posts. The conversion process is identical.

Q: Can I get the post creation date from the ID?

A: Yes! Instagram media IDs contain timestamps. This tool automatically extracts and displays the creation date.

Q: Is this tool free?

A: Yes, completely free with no signup required. All processing happens in your browser.

Examples

Example 1: Conversion Examples

Shortcode → Numeric ID:
  CxYz123abcd → 2847392847392847392
  B1a2b3c4d5e → 1234567890123456789
  DaB3c4d5e6f → 3100000000000000000

Numeric ID → Shortcode:
  2847392847392847392 → CxYz123abcd
  1234567890123456789 → B1a2b3c4d5e

Both refer to the same post — they are mathematically equivalent.

Use shortcodes for: building Instagram URLs
Use numeric IDs for: Instagram API calls, database storage, sorting

Example 2: JavaScript Bidirectional Converter

const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';

// Shortcode → Numeric ID (as string to preserve precision)
function shortcodeToId(shortcode) {
  let id = 0n;
  for (const char of shortcode) {
    const value = ALPHABET.indexOf(char);
    if (value === -1) throw new Error(`Invalid character: '${char}'`);
    id = id * 64n + BigInt(value);
  }
  return String(id);
}

// Numeric ID → Shortcode
function idToShortcode(numericId) {
  let id = BigInt(numericId);
  if (id === 0n) return 'A';
  let result = '';
  while (id > 0n) {
    result = ALPHABET[Number(id % 64n)] + result;
    id /= 64n;
  }
  return result;
}

// Examples:
console.log(shortcodeToId('CxYz123abcd'));
// → "2847392847392847392"

console.log(idToShortcode('2847392847392847392'));
// → "CxYz123abcd"

// Build Instagram URL from API numeric ID:
const numericId = '2847392847392847392';
const shortcode = idToShortcode(numericId);
const url = `https://www.instagram.com/p/${shortcode}/`;
console.log(url);
// → "https://www.instagram.com/p/CxYz123abcd/"

Example 3: Python Bidirectional Converter

ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'

def shortcode_to_id(shortcode: str) -> int:
    """Convert Instagram shortcode to numeric media ID."""
    media_id = 0
    for char in shortcode:
        media_id = media_id * 64 + ALPHABET.index(char)
    return media_id

def id_to_shortcode(numeric_id: int) -> str:
    """Convert numeric media ID to Instagram shortcode."""
    if numeric_id == 0:
        return 'A'
    shortcode = ''
    while numeric_id > 0:
        shortcode = ALPHABET[numeric_id % 64] + shortcode
        numeric_id //= 64
    return shortcode

# Examples:
print(shortcode_to_id('CxYz123abcd'))
# → 2847392847392847392

print(id_to_shortcode(2847392847392847392))
# → 'CxYz123abcd'

# Verify round-trip:
original = 'CxYz123abcd'
assert id_to_shortcode(shortcode_to_id(original)) == original
print("Round-trip verified ✅")

Frequently Asked Questions

Paste the Instagram shortcode (from the post URL) into the converter and click 'Convert to ID'. The shortcode is the alphanumeric string in URLs like instagram.com/p/SHORTCODE/. You'll get the numeric media ID instantly.

An Instagram shortcode is a base64-encoded identifier in post URLs (e.g., CxOWiQNphlr). It's a compact representation of the numeric media ID used internally by Instagram's API.

Converting shortcodes to IDs is useful for Instagram API development, data analysis, post tracking, and extracting creation timestamps from the numeric ID.