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
- Shortcode — use in Instagram URLs, embeds, and user-facing links
- Numeric ID — use for Instagram API calls, database primary keys, and sorting
- Both are permanent and never change after post creation
- Always use BigInt in JavaScript when working with numeric IDs
- Store numeric IDs as strings (VARCHAR) in databases to avoid precision issues
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 - 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 - 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
- API Development: Convert shortcodes from URLs to IDs for Instagram API calls
- Data Analysis: Track Instagram posts using numeric IDs in databases
- Post Tracking: Monitor specific posts across different platforms
- Timestamp Extraction: Get post creation dates from media IDs
- Bot Development: Process Instagram URLs in automation tools
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 ✅")