BGP always starts by building a session between two routers (peers).
Think of it as a conversation: until the session is Established, no routes are exchanged.BGP Session Establishment
Let’s reuse a simple scenario with two Autonomous Systems that interconnect.
Before they can exchange routes, the two routers must establish a TCP session on port 179 and go through several BGP states.
Read the diagram from left to right. As the session comes up, you will see these states:
Figure 1 — BGP session states
Idle: the router is ready and waiting to start.
Connect: it tries to reach the peer and bring up the session.
OpenSent: it sends an OPEN message (ASN, timers, router-id, capabilities).
OpenConfirm: it waits for a KEEPALIVE message to confirm the relationship.
Established: the session is up. Only at this stage are routes exchanged via UPDATE messages.
For CCNP ENCOR, you don’t need CCIE-level packet details.
What you must remember is simple:No Established = no route exchange.
Answer the question below
Which port does BGP use?
Once the session is Established, routes can start flowing.
At this point, BGP does not immediately install everything into the routing table. It processes each prefix through an internal workflow.
Figure 2 - BGP Topology
How a route moves inside the router
Imagine the router in AS 65002 receives a route to reach 192.168.1.0/24 from AS 65001.

Figure 3 — BGP route processing pipeline
Adj-RIB-In: the Inbox
The router first stores routes received from a neighbor here.
R2# show ip bgp neighbors 10.0.12.1 routes BGP table version is 3, local router ID is 192.168.2.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.0.12.1 0 0 65001 i Total number of prefixes 1You are looking at the routes received from that specific neighbor.
This is the “receive” stage: the route has arrived, but the decision process is not finished yet.Loc-RIB: the BGP Table
BGP keeps candidate paths here and selects the best path.
R2# show ip bgp ipv4 unicast BGP table version is 3, local router ID is 192.168.2.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 10.0.12.1 0 0 65001 i *> 192.168.2.0 0.0.0.0 0 32768 iThis is the BGP table where all candidate paths are stored.
Here, BGP selects the best path (indicated by >), but this is still not the forwarding table.RIB: the Routing Table
Only the best path is installed here so the router can actually forward traffic.
R2# show ip route bgp Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR Gateway of last resort is not set B 192.168.1.0/24 [20/0] via 10.0.12.1, 00:05:48Multiple paths can exist in the BGP table, but typically only one path is installed in the routing table.
Now you see the route actually installed for forwarding.
This is what the router will use to send traffic.Adj-RIB-Out: the Outbox
Routes that will be advertised to a neighbor are prepared here.
R2# show ip bgp neighbors 10.0.12.1 advertised-routes BGP table version is 3, local router ID is 192.168.2.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, t secondary path, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.2.0 0.0.0.0 0 32768 i Total number of prefixes 1This shows which networks you are advertising to that neighbor.
The protocol is designed with multiple stages so you can control what you accept, what you prefer, what you install, and what you advertise.
Answer the question below
Where is the best path selected?
BGP is a path-vector protocol. That means it does not build a full topology map like OSPF.
Instead, it tracks the AS-level path a route has already taken, using the AS_PATH attribute.In this example, AS 100 advertises the network 10.10.1.0/24 to AS 200.
AS_PATH propagation
When the router in AS 200 receives the advertisement, it sees an AS_PATH of 100.
If AS 200 advertises the same prefix to another neighbor, it prepends its own ASN to the front of the list.
The path then becomes 200 100, and the same process repeats as the route moves across multiple autonomous systems.
Figure 4 — AS_PATH attribute propagation
Loop prevention rule
Now imagine the ASes are connected in a triangle.
In this type of topology, a route can come back toward an AS it has already visited.
Figure 5 — AS_PATH loop prevention
Here is the key rule BGP uses:
If a router receives a route and finds its own ASN inside the AS_PATH, it rejects the route.
So if the route starts in AS 100, then gets advertised as 200 100, and later comes back toward AS 100 as 300 200 100, AS 100 will see its own ASN in the path. At that moment, AS 100 drops the route because accepting it would create a routing loop.
That simple AS_PATH check is the core loop-prevention mechanism in BGP.
Several paths can sit in the Loc-RIB for the same prefix. In the next lessons, you see how BGP picks one, attribute by attribute.
Answer the question below
Which BGP attribute does a router check for its own ASN to detect a routing loop?