Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityAdvanced

MPLS fundamentals: labels, LSRs, label operations and LDP

In short: MPLS forwards packets using short labels instead of IP lookups at every hop. Edge routers push a label, core routers swap it, and the last hop pops it. LDP builds the labels automatically for every prefix in the IGP. On its own MPLS adds little speed today; its value is the services it enables: VPNs, traffic engineering and a BGP-free core.

Why MPLS exists

Multiprotocol Label Switching (MPLS) places a small label in front of each packet and forwards by that label. It was first promoted as faster than IP lookups, but modern hardware does both at line rate. Its lasting value is that the label separates how a packet is forwarded from what is inside it. That makes possible:

  • Layer 3 VPNs: many customers with overlapping addresses on one shared network.
  • Layer 2 VPNs: carrying Ethernet circuits between sites.
  • Traffic engineering: sending traffic along paths other than the IGP shortest path.
  • A BGP-free core: core routers only need labels to reach the edge routers, not a full internet table.

The label and the routers

An MPLS label header, or "shim", is 32 bits and sits between the Layer 2 and Layer 3 headers:

FieldBitsPurpose
Label20The value routers forward on. 0-15 are reserved; 3 means implicit null.
Traffic Class (TC, formerly EXP)3QoS marking inside the core
Bottom of stack (S)1Set on the last label; packets can carry several labels
TTL8Loop protection, copied from the IP header by default

The router roles are: CE (customer edge, no MPLS), PE (provider edge, also called a label edge router or LER, which pushes and pops labels) and P (provider core, a label switching router or LSR, which swaps labels). The path a labelled packet follows is a label switched path (LSP), and it is one-directional.

Push, swap and pop

A packet crossing an MPLS coreIngress PEpush label 30P routerswap 30 to 41P routerswap 41 to 3 (pop)Egress PEplain IP lookup
Figure 1. The ingress label edge router pushes a label, core routers swap labels without looking at the IP header, and the label is usually removed one hop before the egress router (penultimate hop popping).

Each router chooses its own local label for each prefix and tells its neighbours. A router's LIB (label information base) stores all labels learned; its LFIB (label forwarding information base) holds the ones it actually uses, matching the best IGP path. With penultimate hop popping (PHP), the egress PE advertises label 3, "implicit null", so the router before it removes the label, saving the egress router a double lookup. Explicit null (label 0 for IPv4) is used instead when the egress router must still see the TC bits for QoS.

LDP: distributing labels

The Label Distribution Protocol (LDP), RFC 5036, gives a label to every prefix in the routing table and shares them with neighbours. LDP routers send hellos on UDP port 646 to 224.0.0.2, then form a TCP session on port 646 between their transport addresses, normally their loopbacks. The LDP router ID is usually the highest loopback address, and it must be reachable through the IGP.

mpls label protocol ldp
mpls ldp router-id Loopback0 force
interface GigabitEthernet0/1
 mpls ip
router ospf 1
 mpls ldp autoconfig area 0
!
show mpls ldp neighbor
show mpls forwarding-table
show mpls ldp bindings

mpls ldp autoconfig enables LDP on every OSPF interface in the area, which avoids forgetting one. Two related features protect convergence: LDP-IGP synchronisation stops the IGP using a link until LDP is ready on it, and LDP session protection keeps labels during short link flaps.

LDP label filtering

By default LDP allocates labels for every prefix, including point-to-point links that nobody needs to reach through the core. In large networks this wastes memory. You can restrict LDP to loopback host routes (mpls ldp label then allocate global host-routes) or advertise only selected prefixes with mpls ldp advertise-labels for ACL, so labels exist only for the PE loopbacks that services use.

Newer networks often replace LDP with Segment Routing (SR-MPLS), where the IGP itself distributes labels, removing a protocol from the core.

Real-world example: a regional fibre provider found that after a core link flap, customer VPN traffic between two towns was dropped for several seconds even though OSPF had already recovered. OSPF had moved traffic onto the restored link before LDP had exchanged labels on it, so packets arrived unlabelled at routers that had no IP route for customer prefixes. The engineers enabled LDP-IGP synchronisation, so OSPF advertised the link with a maximum metric until LDP was ready, and the drops stopped.

Practice

What does a P router do with a labelled packet?
It swaps the incoming label for an outgoing label using its LFIB and forwards the packet, without looking at the IP header.
What does implicit null (label 3) cause?
Penultimate hop popping: the router before the egress PE removes the top label, so the egress PE receives the packet without it.
Which port and transport does an LDP session use?
Hellos on UDP 646 to 224.0.0.2, then a TCP session on port 646 between the transport addresses.

Key takeaways

  • MPLS forwards on 20-bit labels in a 32-bit shim between Layer 2 and Layer 3.
  • PE routers push and pop labels; P routers swap them; CE routers do not run MPLS.
  • Penultimate hop popping uses implicit null (label 3) to save the egress router a lookup.
  • LDP gives every IGP prefix a label, using UDP and TCP port 646.
  • Filter LDP labels to loopbacks in large networks; Segment Routing is the modern alternative.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.