What is an Instagram Shortcode?

An Instagram shortcode is a base64-encoded string that uniquely identifies posts, Reels, and other media on Instagram. It's the alphanumeric code you see in Instagram URLs, making them shorter and more shareable than using raw numeric IDs.

Example Instagram URL

https://instagram.com/p/CK1JqHqFVOy/

The shortcode CK1JqHqFVOy represents media ID 2501040375429168306

Why Does Instagram Use Shortcodes?

Instagram uses shortcodes to create cleaner, more user-friendly URLs. Instead of displaying long 19-digit numbers, shortcodes compress media IDs into 11-character strings using base64 encoding.

Without Shortcode

instagram.com/p/2501040375429168306/

Long, hard to remember

With Shortcode

instagram.com/p/CK1JqHqFVOy/

Short, easy to share

How Instagram Shortcodes Work

Instagram shortcodes use a custom base64 alphabet to encode numeric media IDs. The encoding process converts a 19-digit number into an 11-character string.

Instagram's Base64 Alphabet

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_

This is a URL-safe variant of base64, using - and _ instead of + and /

Types of Instagram Shortcodes

Post Shortcodes

instagram.com/p/SHORTCODE/

Used for regular photo and video posts

Reel Shortcodes

instagram.com/reel/SHORTCODE/

Used for Instagram Reels

TV Shortcodes

instagram.com/tv/SHORTCODE/

Used for IGTV videos

Story Shortcodes

instagram.com/stories/SHORTCODE/

Used for Instagram Stories

Decoding Instagram Shortcodes

You can decode Instagram shortcodes to reveal the underlying media ID and creation timestamp. Here's how it works:

JavaScript
// JavaScript - Decode Instagram Shortcode
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';

function shortcodeToMediaId(shortcode) {
  let mediaId = 0n;
  for (const char of shortcode) {
    mediaId = mediaId * 64n + BigInt(ALPHABET.indexOf(char));
  }
  return mediaId.toString();
}

// Example
const shortcode = 'CK1JqHqFVOy';
const mediaId = shortcodeToMediaId(shortcode);
console.log(mediaId); // 2501040375429168306
Python
# Python - Decode Instagram Shortcode
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'

def shortcode_to_media_id(shortcode):
    media_id = 0
    for char in shortcode:
        media_id = media_id * 64 + ALPHABET.index(char)
    return media_id

# Example
shortcode = 'CK1JqHqFVOy'
media_id = shortcode_to_media_id(shortcode)
print(media_id)  # 2501040375429168306

What Information is in a Shortcode?

Instagram shortcodes encode the media ID, which contains timestamp information about when the post was created. By decoding the shortcode, you can:

  • Get the numeric media ID for API calls
  • Extract the creation timestamp
  • Determine the approximate post date
  • Sort posts chronologically
  • Track content creation patterns

Common Use Cases

API Development

Convert shortcodes to media IDs for Instagram Graph API requests

Analytics

Track post performance using media IDs in analytics platforms

Bot Development

Process Instagram posts programmatically using media IDs

Research

Analyze Instagram content patterns and posting behavior

Shortcode vs Media ID

Shortcode

  • 11 characters long
  • Base64 encoded
  • Used in URLs
  • Human-friendly
  • Example: CK1JqHqFVOy

Media ID

  • 19 digits long
  • Numeric format
  • Used in API calls
  • Machine-friendly
  • Example: 2501040375429168306

Try Our Instagram Shortcode Tools

Use our free online tools to work with Instagram shortcodes:

  • Instagram Shortcode Decoder: Convert shortcodes to media IDs
  • Instagram Shortcode to ID Converter: Bidirectional conversion
  • Instagram Reel Shortcode Decoder: Decode Reel shortcodes

Last updated

What is an Instagram Shortcode — Examples

Instagram shortcodes are the alphanumeric identifiers in Instagram post URLs. They are Base64-encoded versions of the underlying numeric media ID. Here are examples showing how they work.

Anatomy of an Instagram URL

// Instagram post URL structure
// https://www.instagram.com/p/SHORTCODE/

// Example:
// https://www.instagram.com/p/CxYz1234abc/
//                              ^^^^^^^^^^^
//                              This is the shortcode

// The shortcode encodes the numeric media ID
// CxYz1234abc → some large numeric ID

Decoding a Shortcode to Media ID

// JavaScript — decode Instagram shortcode to numeric ID
function shortcodeToId(shortcode) {
  // Instagram uses URL-safe Base64 alphabet
  const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  
  let id = 0n;
  for (const char of shortcode) {
    id = id * 64n + BigInt(ALPHABET.indexOf(char));
  }
  return id.toString();
}

// Example
console.log(shortcodeToId("CxYz1234abc"));
# Python — decode Instagram shortcode to numeric ID
def shortcode_to_id(shortcode):
    """Decode an Instagram shortcode to its numeric media ID."""
    ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
    
    id_val = 0
    for char in shortcode:
        id_val = id_val * 64 + ALPHABET.index(char)
    
    return id_val

# Example
print(shortcode_to_id("CxYz1234abc"))

Encoding a Media ID to Shortcode

# Python — encode a numeric media ID to shortcode
def id_to_shortcode(media_id):
    """Encode a numeric media ID to an Instagram shortcode."""
    ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
    
    shortcode = ""
    id_val = int(media_id)
    
    while id_val > 0:
        shortcode = ALPHABET[id_val % 64] + shortcode
        id_val //= 64
    
    return shortcode

# Round-trip test
media_id = 1234567890123456789
shortcode = id_to_shortcode(media_id)
decoded = shortcode_to_id(shortcode)

print(f"Media ID: {media_id}")
print(f"Shortcode: {shortcode}")
print(f"Decoded back: {decoded}")
print(f"Match: {str(media_id) == decoded}")

Extracting Shortcode from URL

// JavaScript — extract shortcode from any Instagram URL
function extractShortcode(url) {
  const patterns = [
    /instagram\.com\/p\/([A-Za-z0-9_-]+)/,
    /instagram\.com\/reel\/([A-Za-z0-9_-]+)/,
    /instagram\.com\/tv\/([A-Za-z0-9_-]+)/,
  ];
  
  for (const pattern of patterns) {
    const match = url.match(pattern);
    if (match) return match[1];
  }
  return null;
}

// Examples
const urls = [
  "https://www.instagram.com/p/CxYz1234abc/",
  "https://www.instagram.com/reel/CxYz1234abc/?igshid=abc",
  "https://www.instagram.com/p/CxYz1234abc/?utm_source=ig_web",
];

urls.forEach(url => {
  console.log(extractShortcode(url));
});

Timestamp from Instagram Media ID

# Python — extract creation timestamp from Instagram media ID
# Instagram media IDs encode a timestamp similar to Twitter Snowflake IDs

def get_instagram_post_date(shortcode):
    """
    Extract the approximate creation date from an Instagram shortcode.
    Instagram media IDs encode a timestamp in their upper bits.
    """
    media_id = shortcode_to_id(shortcode)
    
    # Instagram uses a similar approach to Twitter Snowflake
    # The timestamp is in the upper bits of the media ID
    # Instagram's epoch is approximately January 1, 2011
    INSTAGRAM_EPOCH_MS = 1293840000000  # approximate
    
    # Extract timestamp (upper bits)
    timestamp_ms = (media_id >> 23) + INSTAGRAM_EPOCH_MS
    
    from datetime import datetime, timezone
    dt = datetime.fromtimestamp(timestamp_ms / 1000, tz=timezone.utc)
    return dt.strftime("%Y-%m-%d %H:%M:%S UTC")

# Note: This is an approximation — exact epoch may vary

Using Shortcodes in the Instagram API

# Python — use shortcode with Instagram Graph API
import requests

def get_post_by_shortcode(shortcode, access_token):
    """
    Look up an Instagram post by its shortcode using the Graph API.
    First convert shortcode to media ID, then query the API.
    """
    media_id = shortcode_to_id(shortcode)
    
    url = f"https://graph.instagram.com/{media_id}"
    params = {
        "fields": "id,media_type,timestamp,permalink",
        "access_token": access_token
    }
    
    response = requests.get(url, params=params)
    return response.json()

# Example
# post = get_post_by_shortcode("CxYz1234abc", "YOUR_ACCESS_TOKEN")

Shortcode Alphabet Reference

Instagram shortcodes are a compact, URL-safe representation of the underlying numeric media ID. Understanding the encoding allows you to convert between shortcodes and IDs, extract timestamps, and build tools that work with Instagram content programmatically.

Frequently Asked Questions

An Instagram shortcode is a base64-encoded string that represents a post's numeric media ID. It appears in Instagram URLs like instagram.com/p/SHORTCODE/. For example, 'CK1JqHqFVOy' is a shortcode that encodes the media ID 2501040375429168306.

Instagram uses shortcodes to make URLs shorter and more user-friendly. A 19-digit media ID like 2501040375429168306 becomes an 11-character shortcode like CK1JqHqFVOy, making URLs easier to share and remember.

Instagram shortcodes appear in post URLs. For posts: instagram.com/p/SHORTCODE/. For Reels: instagram.com/reel/SHORTCODE/. The alphanumeric string between the slashes is the shortcode.

Yes! Instagram shortcodes can be decoded to reveal the numeric media ID and creation timestamp. Use our free Instagram shortcode decoder tool to convert shortcodes to media IDs instantly.