Skip to main content

Understanding PLMN IDs, MCC and MNC

Updated 5 min readMarkdown

A PLMN ID is how a mobile network says who it is. It is short, it appears in almost every piece of signaling, and it is built from two numbers that look arbitrary until you know where they come from. This post explains the MCC, the MNC and the PLMN ID they form, how they sit inside the IMSI, and the edge cases that break naive parsers.

Definitions

  • MCC (Mobile Country Code): three digits that identify a country, or in a few cases a group of territories. The values are assigned by the ITU in recommendation E.212.
  • MNC (Mobile Network Code): two or three digits that identify a network within that country. National regulators assign them.
  • PLMN ID: the MCC and MNC together. PLMN stands for Public Land Mobile Network, meaning one operator's network in one country.

One operator can hold several PLMN IDs, and one country has many. A company that operates in ten countries has at least ten PLMN IDs.

Where the PLMN ID shows up

  • In the IMSI: the first digits of the IMSI are the MCC followed by the MNC, so the SIM carries its home network's identity.
  • In cell broadcasts: every cell announces the PLMN IDs it serves, which lets a phone decide whether it may camp there.
  • In roaming decisions: a visited network compares the PLMN ID in the IMSI against its roaming partners to decide where to route authentication.
  • In DNS names: the 3GPP domain names for gateways and interworking functions embed the MCC and MNC, as in the APN post of this series.

The two-digit versus three-digit MNC problem

The MNC can be two or three digits, and the IMSI does not mark the boundary. Given the digits 310260123456789, nothing in the string tells you whether the MNC is 26 or 260. The SIM stores that length (in a field of its administrative data), and the network knows it from its own configuration. In some parts of the world, such as North America, three-digit MNCs are common, and in many other regions two-digit ones are.

Parsers that hard-code the length produce wrong results for a share of subscribers. A safer approach is a lookup table keyed on the MCC and the leading digits:

# Illustrative table only: use an authoritative source for real data.
MNC_LENGTH_BY_MCC = {
    "310": 3,   # example: a region using three-digit MNCs
    "234": 2,   # example: a region using two-digit MNCs
}

def parse_plmn_from_imsi(imsi: str, sim_mnc_len=None):
    mcc = imsi[:3]
    mnc_len = sim_mnc_len or MNC_LENGTH_BY_MCC.get(mcc)
    if mnc_len is None:
        raise ValueError(f"unknown MNC length for MCC {mcc}")
    return mcc, imsi[3:3 + mnc_len]

If you can read the SIM, prefer the length it stores. A table is the fallback for when you only have the number.

How the PLMN ID is encoded in signaling

On the wire, a PLMN ID is packed into three bytes, with each digit in a half byte. The digits are not in reading order. The layout of the 3GPP encoding is:

byte 1:  MCC digit 2 | MCC digit 1
byte 2:  MNC digit 3 | MCC digit 3
byte 3:  MNC digit 2 | MNC digit 1

When the MNC has only two digits, the unused half byte (MNC digit 3) is filled with 0xF. Here is an encoder and decoder that follows that layout:

def encode_plmn(mcc: str, mnc: str) -> bytes:
    m3 = int(mnc[2]) if len(mnc) == 3 else 0xF
    return bytes([
        (int(mcc[1]) << 4) | int(mcc[0]),
        (m3 << 4) | int(mcc[2]),
        (int(mnc[1]) << 4) | int(mnc[0]),
    ])

def decode_plmn(b: bytes):
    mcc = f"{b[0] & 0xF}{b[0] >> 4}{b[1] & 0xF}"
    m3 = b[1] >> 4
    mnc = f"{b[2] & 0xF}{b[2] >> 4}" + ("" if m3 == 0xF else str(m3))
    return mcc, mnc

A quick round trip test should always be part of your suite, using a two-digit and a three-digit MNC.

Special values

Some PLMN IDs are reserved. The MCC 001 with the MNC 01 is the conventional test network used in labs and open-source cores, and it must not appear in live traffic. Handle test values in your logs deliberately, so they do not get mixed into production data.

Storing PLMN IDs in a database

  • Keep the MCC and MNC as separate text columns, or a single text column in the form 310-260. Do not store them as integers, because a leading zero in the MCC or MNC is meaningful.
  • Do not assume a one-to-one link between PLMN and company. Mergers, MVNOs and shared networks all make this untidy.
  • Treat the table that maps PLMN to operator name as reference data with a source and an update date.

Takeaways

  • The PLMN ID is the MCC and the MNC, and it opens the IMSI.
  • The MNC length is not recoverable from the digits alone.
  • On the wire it uses a nibble-swapped three-byte encoding with 0xF as filler.

About the author: I work on content and web development at eSIMCircle, a travel eSIM provider. This series comes from the engineering side of that work.

About the author

  • eSIMCircle provides affordable global eSIM plans with reliable data in 200+ countries.

No comments yet. Be the first to comment.

More from this blog