Skip to content
7LayerX

Routing / Field note

BGP basics: autonomous systems, peers, and routes

Learn what BGP does, how autonomous systems and peers exchange routes, and then explore interactive route selection, configuration, and practice.

7LayerX Editorialupdated 4 min readBGP

BGP stands for Border Gateway Protocol. It helps separate networks share information about which IP address ranges they can reach. These networks are called autonomous systems, or ASes.

Each AS has an autonomous system number (ASN). An ISP, a cloud provider, or a large business network can operate an AS. Its routers use routing policy to decide which routes to accept, prefer, and share.

BGP is often called a path-vector protocol. A route carries information about the ASes it has crossed, along with other path attributes. BGP uses those values and local policy to choose a route. It does not simply measure which cable is shortest or which path has the lowest delay.

What BGP shares

A BGP route contains a destination prefix, such as the simulator's 192.0.2.0/24, and information that helps another router decide what to do with it. Important parts include:

  • Prefix: the group of IP addresses the route describes.
  • NEXT_HOP: the router address that should receive traffic next.
  • AS_PATH: the sequence of AS numbers the route crossed.
  • Local Preference and MED: policy values that help choose an exit or suggest an entry point.
  • ORIGIN: a code that describes how the route entered BGP.

BGP neighbors exchange routes after they establish a session over TCP port 179. The routers share a full set of routes when the session starts, then send updates when route information changes.

eBGP and iBGP

Both are BGP sessions. The difference is whether the neighbors belong to the same AS.

TopiceBGPiBGP
NeighborsRouters in different ASesRouters in the same AS
Common useExchange routes between organizations or providersShare external and internal BGP routes inside one network
AS_PATHThe local AS is added when a route is sent to another ASThe local AS is not added for a normal iBGP update
NEXT_HOPCommonly set to the advertising routerCommonly kept as received; next-hop-self can change it
Re-advertising a learned routeA router may advertise an eligible route to another eBGP peer, subject to policyA route learned from one iBGP peer is not normally sent to another iBGP peer

The iBGP rule prevents routing loops. A small iBGP network can use a full mesh, where each router peers with every other router. Larger networks often use route reflectors to reduce the number of sessions.

Follow one route

In the learning topology, ISP-A (AS 64512) originates 192.0.2.0/24. It shares the route with ISP-B (AS 64520) and ISP-C (AS 64540). Corp-X (AS 64531) receives one candidate path through each provider. Its edge router checks policy and next-hop reachability before comparing both paths to the same prefix.

If the route wins, BGP can advertise it to eligible peers. The operating system also checks whether that route should be installed for packet forwarding. Filters, policy, or another routing source may affect those later decisions.

route update arrives
        ↓
check policy and route eligibility
        ↓
compare paths to the same prefix
        ↓
advertise the chosen route and install it when allowed

Where BGP fits

An internal routing protocol, such as OSPF or IS-IS, often gives routers inside one AS a way to reach each other and to reach BGP next hops. BGP can then exchange routes between ASes and apply policy to those routes.

This division is common, but each network chooses its design. BGP route selection and packet forwarding are related tasks, but they are not the same step.

Keep learning

Common questions about BGP basics

Quick answers about BGP networks, peer types, and route sharing.

3 answers

Does BGP always choose the shortest route?

No. Policy values can decide the route before BGP compares AS_PATH length. A short AS_PATH also does not prove that the physical route is short or fast.

Do I need BGP inside every company network?

No. Many networks use an internal routing protocol and do not run BGP. BGP is useful when a network needs to exchange routes between ASes or apply detailed route policy.

Is iBGP the same as an IGP?

No. iBGP is BGP between routers in the same AS. An IGP is an interior routing protocol, such as OSPF, that commonly provides routes between routers inside the AS.

Interactive route lab

Change the policy. Watch the route move.

Compare two routes to the same prefix. Adjust attributes, inspect the routing table, or take a provider link down.

Try a scenario
Path A · ISP-B · AS 64520
Path B · ISP-C · AS 64540
MED is normally compared between routes from the same neighboring AS.
eBGP link iBGP link Link down Live prefix flow
Select a router for its RIB · select a link dot to bring it up or down.
AS 64512 · ISP-AADVERTISED PREFIX192.0.2.0/24AS 64520 · ISP-BAS 64540 · ISP-CAS 64531A1ISP-A R110.0.1.1A2ISP-A R210.0.1.2B1ISP-B R110.0.2.1B2ISP-B R210.0.2.2C1ISP-C R110.0.4.1X1Corp-X R110.0.3.1

Best-path decision

Path A via ISP-B wins · IGP cost
  1. WeightEqual
  2. Local PreferenceEqual
  3. Local routeEqual
  4. AS_PATHEqual
  5. OriginEqual
  6. MEDNot compared
  7. eBGP / iBGPEqual
  8. IGP costDecides
  9. AgeNot reached
  10. Router IDNot reached
  11. Peer IPNot reached

Animated route walkthrough

See how BGP chooses a path.

Animated topology walkthrough showing the 192.0.2.0/24 route from ISP-A through the ISP-B and ISP-C candidate paths to Corp-X. The default best path is ISP-B because its IGP cost is lower.

Animated topology walkthrough for the default scenario. It illustrates the route flow; use the live lab above to change attributes or link state.

BGP field guide

Follow one route across the whole network.

Follow each concept with the interactive lab above this guide. The names, AS numbers, prefix, route values, and outcomes match the simulator.

Autonomous System

A network and its routers, managed under one routing policy.

Prefix

A network range. The lab advertises 192.0.2.0/24, a documentation example.

eBGP

A BGP session between routers in different autonomous systems.

iBGP

A BGP session between routers in the same autonomous system.

Read the topology

Two providers. One destination.

ISP-A originates the example prefix. It shares the route with two transit providers. Corp-X receives one route from each provider and compares them at its edge router.

Return to the interactive simulator
  1. 01

    ISP-A · AS 64512

    Router A1 originates 192.0.2.0/24. The A1–A2 link shares the route inside ISP-A.

  2. 02

    Path A · ISP-B · AS 64520

    The route crosses eBGP from A1 to B1, then from B1 to Corp-X router X1.

  3. 03

    Path B · ISP-C · AS 64540

    The route crosses iBGP from A1 to A2, then eBGP from A2 to C1 and C1 to X1.

  4. 04

    Corp-X · AS 64531

    Router X1 compares the two available paths. Its chosen path appears in the RIB table and as the forwarding path.

How X1 compares routes

The first difference can decide.

The lab follows this Cisco-style teaching order. Real devices can add settings or use a different order, so check the platform guide.

  1. 01

    Weight

    Higher wins. Cisco-specific and local to one router.

  2. 02

    Local Preference

    Higher wins. Shared inside an AS to guide outbound traffic.

  3. 03

    Locally originated

    A route created on this router can be preferred.

  4. 04

    AS_PATH

    A shorter path is usually preferred.

  5. 05

    Origin

    IGP is preferred over EGP, then Incomplete.

  6. 06

    MED

    Lower is preferred, usually between routes from the same neighbor AS.

  7. 07

    eBGP or iBGP

    An eBGP path is commonly preferred over an iBGP path.

  8. 08

    IGP cost

    A lower cost to the BGP next hop is preferred.

  9. 09

    Route age

    Some implementations prefer the older external path for stability.

  10. 10

    Router ID

    A lower ID may break a remaining tie, depending on the platform.

  11. 11

    Peer IP

    A lower neighbor address may be the final tie-break.

The simulator gives both candidate routes an equal value for local origination and eBGP/iBGP, because both routes are learned from external peers at X1. Those checks therefore do not decide the default example.

Try the matching presets

Change one thing. Follow the result.

Go to the scenario buttons

Default

The two paths have equal policy values.

Path A through ISP-B wins because its IGP cost is 10, compared with 20 for Path B.

Open the simulator

Local Preference

Path B receives Local Preference 200; Path A stays at 100.

Path B through ISP-C wins at the Local Preference check.

Open the simulator

AS_PATH

The simulator prepends Path A twice, making its example path longer.

Path B wins because its AS_PATH is shorter. Prepending may influence other networks, but it cannot guarantee their choice.

Open the simulator

MED

Path A MED is 50 and Path B MED is 10.

Path B wins in this teaching scenario. The simulator enables comparison across the two provider ASes; routers commonly compare MED only for routes from the same neighboring AS.

Open the simulator

Failover

The link from ISP-B router B1 to Corp-X router X1 is switched off.

Path A becomes unavailable, so forwarding moves to Path B through ISP-C.

Open the simulator

Failover here is an immediate teaching model. It does not run BGP, send a real withdrawal, or measure network convergence timers.

From neighbor to session

BGP uses TCP port 179.

Two configured peers first need IP reachability and a TCP connection. They then use BGP messages to agree on a session and exchange reachable prefixes. A session can be up even when a policy rejects every route.

Four message types

OPEN
Starts a session and shares router and capability details.
UPDATE
Adds or changes routes, or withdraws routes that are no longer reachable.
KEEPALIVE
Confirms that the session is still active.
NOTIFICATION
Reports an error and usually closes the session.

The six session states

  1. Idle

    BGP is ready to start a connection.

  2. Connect

    The router is trying to complete a TCP connection to its peer.

  3. Active

    The connection did not complete, so the router tries again.

  4. OpenSent

    TCP is up and the router has sent a BGP OPEN message.

  5. OpenConfirm

    The routers wait for a KEEPALIVE to confirm the session.

  6. Established

    The session is ready to exchange route updates.

Timer values are negotiated and can be configured. Do not assume a fixed keepalive or hold time for every peer.

RIB and forwarding path

The BGP table can show more than one candidate. In this lab, `*` marks a usable route and `>` marks the selected best route. The forwarding-path label names the route the model currently uses.

Which direction does policy affect?

Weight and Local Preference choose where your own network sends traffic. AS_PATH prepending and MED can influence how a neighboring network sends traffic toward you, but that network makes its own decision.

Use the route rules

Make the next path choice yourself.

Each round changes one part of the decision. Pick a route and see the reason before moving to the next one.

Practice route choice

Can you pick the winning path?

Compare two routes to the same network. Look for the first rule that makes them different.

Your score

0 / 6

Decision 1 of 6

Decision rule

Cisco Weight

Destination prefix

192.0.2.0/24

Path A has more Weight. Which provider path wins?

Compare Weight first. This is a Cisco-specific value and stays on one router.

A lab before a live network

See the commands. Know what they change.

These command examples use a separate two-router practice lab; its names and addresses differ from the route simulator. Check interfaces, prefixes, and existing policy before applying them.

Choose your platform

These examples use Cisco IOS-XE and FRRouting. Read the lab note before copying a command.

Bring up an eBGP sessionTwo routers in different AS numbers exchange one practice prefix each.
Lab note: The connected link and loopback networks must already exist. The address ranges are for documentation and lab use only.
! R1 — AS 65010. Loopback0: 192.0.2.1/24
router bgp 65010
 bgp router-id 192.0.2.1
 neighbor 198.51.100.2 remote-as 65020
 network 192.0.2.0 mask 255.255.255.0
!
! R2 — AS 65020. Loopback0: 203.0.113.1/24
router bgp 65020
 bgp router-id 203.0.113.1
 neighbor 198.51.100.1 remote-as 65010
 network 203.0.113.0 mask 255.255.255.0

Prefer one provider with Local PreferenceGive one incoming route a higher local value so your AS uses that exit.
Lab note: This sample changes one named prefix. A route map can reject routes that do not match; review every route it will permit before applying it.
ip prefix-list LAB-DESTINATION seq 5 permit 203.0.113.0/24
route-map PREFER-ISP-B permit 10
 match ip address prefix-list LAB-DESTINATION
 set local-preference 200
!
router bgp 65010
 neighbor 198.51.100.6 route-map PREFER-ISP-B in
!
! Re-evaluate received routes after the policy change:
clear ip bgp 198.51.100.6 soft in
show ip bgp 203.0.113.0

Share routes with iBGPConnect two routers in the same AS and make their loopbacks reachable first.
Lab note: The IGP or static routes must already reach both loopbacks. Full-mesh or route-reflector design is needed as the iBGP network grows.
! R1 — loopback 192.0.2.1, AS 65010
router bgp 65010
 neighbor 192.0.2.2 remote-as 65010
 neighbor 192.0.2.2 update-source Loopback0
 neighbor 192.0.2.2 next-hop-self
!
! R2 — loopback 192.0.2.2, AS 65010
router bgp 65010
 neighbor 192.0.2.1 remote-as 65010
 neighbor 192.0.2.1 update-source Loopback0
!
! Confirm the IGP route to the remote loopback before checking BGP.
show ip route 192.0.2.2
show ip bgp summary

These examples are for learning and need platform and version checks. Do not paste them into a production router without an approved change plan and route-policy review.

Pass it along

Found this useful? Share it.

Choose a platform or copy the direct link.

LinkedInXFacebook

Continue reading

Reader signal

Was this useful?

Your feedback helps shape the next field note and lab.

… views

Views count when this page opens. You can change or remove your vote during this tab session.