The Four Routing Modes
Every IP packet has a destination address, and that address determines how routers handle it. There are four addressing schemes, each with a different delivery semantic:
| Mode | Destination | Delivery | Example Use |
|---|---|---|---|
| Unicast | One specific host | To that host only | Loading a web page |
| Multicast | A subscribed group | To all group members | IPTV, video conferencing |
| Broadcast | All hosts on subnet | To every local host | ARP requests, DHCP discovery |
| Anycast | Nearest of a group | To the topologically closest member | DNS root servers, CDNs |
Anycast is the most unusual of the four. From the sender's perspective it looks like a normal unicast packet — one destination IP — but that IP is announced from multiple locations simultaneously, and BGP routing ensures packets travel to whichever announcement is topologically nearest.
How Anycast Works: BGP and Nearest-Exit Routing
Anycast is implemented at the routing layer using the Border Gateway Protocol (BGP). An organization runs servers in, say, New York, London, Singapore, and São Paulo. All four servers are assigned the same IP prefix — for example, 203.0.113.0/24. Each data center announces this prefix to its upstream ISPs via BGP.
From the perspective of the global routing table, that prefix now appears reachable via four different paths. When a packet destined for an IP in 203.0.113.0/24 arrives at any router in the world, that router's BGP table will point it toward whichever of the four data centers is topologically closest — fewest AS hops, best path attributes. The packet travels toward that location without any additional logic.
Critically, "nearest" in BGP terms means fewest routing hops, not shortest physical distance. A server 500 km away with two AS hops may be preferred over a server 200 km away that requires seven hops.
Why DNS Root Servers Use Anycast
The DNS protocol has exactly 13 root server IP addresses, labeled A through M. There are far more than 13 physical servers — there are hundreds. Each letter represents an anycast group. For example, the F root server at 192.5.5.241 is actually hosted on over 100 machines across six continents, all announcing the same IP prefix via BGP.
This design means that when your DNS resolver queries a root server, it reaches the geographically nearest instance without any coordination logic — BGP handles it. Without anycast, every DNS query in Asia would have to travel to a root server in North America or Europe, adding 150–250ms to every cold DNS lookup.
How CDNs Use Anycast
CDNs use anycast to ensure HTTP requests reach the nearest edge node. Cloudflare, for example, announces its entire IP range from every data center via BGP. A user in Frankfurt gets served by a Frankfurt node. A user in Mumbai gets served by a Mumbai node. Neither user configures anything; routing handles it transparently.
Not all CDNs use anycast. Some use DNS-based geo-routing instead: their authoritative DNS server inspects the querying resolver's IP address and returns the IP of the nearest PoP. This works well but adds a DNS round trip and depends on resolver location being a good proxy for user location. Anycast avoids both limitations.
Anycast vs Geolocation-Based DNS
| Feature | Anycast | GeoDNS |
|---|---|---|
| Routing mechanism | BGP (network layer) | DNS (application layer) |
| Nearest-server selection | Automatic via routing tables | Based on resolver IP geolocation |
| Failover speed | BGP convergence (seconds–minutes) | DNS TTL expiry (minutes–hours) |
| Works for UDP | Yes | Yes |
| Works for TCP | Yes (for short-lived connections) | Yes |
| Client configuration required | None | None |
A Limitation: TCP and Long-Lived Connections
Anycast works best for stateless, short-lived exchanges — DNS queries and individual HTTP requests. For long-lived TCP connections, anycast has a subtle problem: if a route change mid-connection causes packets to start routing to a different anycast node, that node has no context for the TCP session and will drop the packets, breaking the connection.
This is one reason HTTP/3 uses QUIC, which includes a connection identifier independent of IP address and path. QUIC connections survive route changes and IP migrations that would break TCP. For DNS (stateless UDP) and short HTTP requests, anycast works flawlessly.
Frequently Asked Questions
What is anycast?
Anycast assigns the same IP address to multiple servers in different locations. BGP routing delivers packets to whichever server is topologically nearest, with no client-side configuration required.
How is anycast different from unicast?
Unicast delivers to one specific host. Anycast delivers to the nearest of several hosts sharing the same IP. From the sender's perspective both look identical — the difference is in how BGP routers handle the destination.
Do CDNs use anycast?
Many do. Cloudflare announces its entire IP range from every data center via BGP, so requests automatically reach the nearest node. Other CDNs use DNS geo-routing instead, returning different IPs based on resolver location.
Why do DNS root servers use anycast?
There are 13 root server IP addresses but hundreds of physical servers. Each is an anycast group — dozens of machines worldwide share the same IP. This ensures DNS root queries are answered from a nearby server, not a single fixed location.
What is the difference between anycast and load balancing?
Load balancing distributes traffic across servers at a single location. Anycast distributes traffic across servers at different geographic locations using BGP. CDNs often use both: anycast to route to the nearest PoP, load balancing within that PoP.
Can anycast fail?
Yes. If a node goes offline and withdraws its BGP announcement, traffic reroutes to the next-nearest location. Failover is automatic but takes seconds to minutes during BGP convergence, during which some packets may be lost.