Shikanoko Networks (SKNK)
← Blog·AnycastBGPCDNDNSASNNetworking

What Is Anycast? How One IP Address Reaches the Nearest Server

Learn what anycast is, how it differs from unicast and multicast, how BGP makes it work, and why DNS, CDNs, and DDoS protection all rely on it.

Introduction

Here's a strange idea: what if the same IP address existed in London, Singapore, and São Paulo at the same time — and every user on Earth reached the closest copy without anyone configuring anything?

That's not science fiction. It's called anycast, and it's the quiet trick behind the DNS root servers, the world's largest content delivery networks, and the edge infrastructure that keeps services close to users.

Most people have never heard of anycast, yet they use it dozens of times a day — every time a DNS lookup resolves in milliseconds, or a video starts without buffering from a server on another continent.

If you've read BGP Basics, you know that networks advertise prefixes to each other. Anycast is what happens when the same prefix is advertised from many places at once. This guide unpacks how that simple idea produces enormous reach.


Unicast, Multicast, Broadcast, Anycast

To appreciate anycast, it helps to see it next to its siblings. These four addressing methods cover every way a packet can find its destination on a network — each built for a different job.

Addressing Methods Compared

Method Sender → Receiver Scope Used on the Internet? Example
Unicast One → One Global Yes — most traffic Loading a webpage, sending an email
Broadcast One → All on segment Local network only No (blocked by routers) ARP requests, DHCP discovery
Multicast One → Subscribed group Can span networks Limited (needs ISP support) IPTV, stock ticker feeds
Anycast One → Nearest of many Global via BGP Yes — DNS, CDNs, DDoS 8.8.8.8, Cloudflare 1.1.1.1, DNS root servers

The mental model: unicast is calling one person's phone. Anycast is calling a support line where the closest available agent always picks up, and you never know (or care) which one it is.

The crucial part is "nearest." Anycast doesn't send your packet to all locations — routers naturally deliver it to the topologically closest one, because that's what BGP's path selection already does.


How Anycast Actually Works

Anycast has no special packet format. No new header. No protocol extension. It's purely a routing trick — and that's what makes it elegant.

The mechanism, step by step:

  1. An organization owns a prefix — say, 2001:db8::/48 — and an ASN.
  2. It stands up identical service instances in multiple locations (London, Singapore, São Paulo).
  3. From each location, it advertises the same prefix into BGP: "AS64496 originates 2001:db8::/48" — from every site.
  4. The rest of the Internet now sees many routes to that prefix, one per location.
  5. Normal BGP path-selection rules mean: a user in Europe reaches the European instance, a user in Asia reaches the Asian instance — same destination IP, different physical endpoint.

Because BGP selects the best path according to its routing policy, the nearest instance is reached automatically. You don't need a global load balancer to decide — the routing table does it for free.

This is why anycast scales so effortlessly: adding a new location is just "advertise the same prefix from there." Every existing user instantly gains a closer endpoint, with zero client-side changes.

The routing foundation matters here. Review What Is an ASN? to see why owning a network identity is what makes anycast deployable in the first place.


Why DNS, CDNs, and DDoS Protection Love Anycast

Anycast is the default architecture for infrastructure that must be both fast and survivable. Each use case exploits a different property of the same routing trick.

Anycast Use Cases at a Glance

Use Case Core Problem How Anycast Solves It Real-World Example
DNS Root Servers 13 IPs must serve the entire planet Each root IP is anycasted across hundreds of locations F-Root, K-Root, L-Root
Public DNS Resolvers Billions of queries/day, zero tolerance for downtime Anycast spreads queries globally, absorbs DDoS 8.8.8.8 (Google), 1.1.1.1 (Cloudflare)
Content Delivery (CDN) Latency kills user experience User hits nearest edge cache automatically Cloudflare, Akamai, Fastly
DDoS Mitigation One server can be overwhelmed Attack traffic is distributed across all anycast sites; no single location absorbs the full volume Cloudflare Magic Transit, AWS Shield
VoIP / Real-Time APIs Every millisecond of latency matters Responder endpoint is always topologically close Twilio, WebRTC signaling
AI Inference at the Edge GPU clusters are centralized; users are global Anycast routes inference requests to the nearest GPU node Emerging: Cloudflare Workers AI, Groq

DNS root and resolver servers. The DNS root server system is one of the largest anycast deployments on Earth. Thirteen root server IPs are each anycasted across hundreds of locations worldwide, spreading load and absorbing attacks that would otherwise knock out resolution globally. Public resolvers like 8.8.8.8 and 1.1.1.1 use the same trick — the IP you query is the same worldwide, but your packets land on a server in your region.

Content Delivery Networks. CDNs use anycast so that a user in Berlin and a user in Buenos Aires both hit "the same" edge IP, but land on physically nearby caches. That's why content loads fast everywhere — the routing table handles geographic distribution without any client-side logic.

DDoS mitigation. When an anycasted IP is attacked, the flood is naturally distributed across all locations. No single site absorbs the full volume. The attack traffic gets spread thin across the network, and each site only handles a fraction. Attackers can't concentrate fire on one target because the target doesn't exist in one place.

Latency-sensitive services. VoIP, gaming, and real-time APIs use anycast to put responder endpoints close to every user, cutting round-trip time without per-user configuration. Combined with a local load balancer for fine-grained distribution, this gives you global reach with regional latency.


Anycast and AI Inference at the Edge

AI inference has a geography problem. GPU clusters are expensive, so they're built in a handful of locations — but users are everywhere. A query from Mumbai routed to a GPU cluster in Virginia adds hundreds of milliseconds of latency, and for real-time applications like voice agents or code autocomplete, that's unusable.

Anycast offers a path forward. By advertising the same inference endpoint from GPU clusters in multiple regions, providers can route each request to the nearest available compute — no client-side region selection, no DNS-based steering. Cloudflare Workers AI and Groq are early adopters of this pattern, placing inference endpoints behind anycast IPs so users hit the closest GPU node automatically.

The same BGP trick that made DNS resilient is now being applied to make AI inference fast. Same principle, new workload.


Trade-offs You Should Know

Anycast isn't magic, and it has sharp edges. Here's what you trade for that automatic geographic distribution:

Trade-off What It Means Mitigation
Stateless services work best DNS and CDN requests are stateless — any instance can answer any query. A long-lived TCP session can break if routing shifts mid-connection and packets land on a different instance. Use anycast for connection establishment, then steer to a unicast backend; or design services to be stateless at the anycast layer.
Routing ≠ geography "Nearest" is topological (BGP path), not physical distance. A user might land on a server 500 km further away because a peering relationship made that path shorter in BGP's view. Tune with BGP communities and Local Preference; monitor with looking glasses to verify which location traffic is actually reaching.
Debugging is harder A single IP resolving to many physical machines breaks traditional per-host troubleshooting. Traceroute from different locations gives different results. Use RIPE Atlas, looking glasses, and anycast-aware monitoring.
You need BGP control Deploying your own public anycast requires advertising a prefix via BGP from multiple sites — which means owning or sponsoring an ASN and having multi-site BGP connectivity. Sponsor an ASN through a LIR, or use a provider that handles anycast for you (CDN, DNS host). Read How to Get Your Own ASN.
IPv4 is scarce and expensive Anycast with IPv4 requires a /24 minimum to be widely accepted — expensive and hard to obtain. Deploy anycast primarily over IPv6, where address space is abundant and prefix acceptance is straightforward.

None of these are dealbreakers for the right workloads. They're the fine print — and knowing them is what separates a reliable anycast deployment from one that breaks mysteriously.


Does Anycast Always Reach the Closest Server?

Not necessarily — and this is where anycast meets real-world BGP policy.

"Nearest" in anycast is decided by routing, not geography. BGP selects the best path using policy attributes such as Local Preference, AS-path length, and commercial peering relationships — not physical distance. A user may occasionally be served from a location that isn't the closest in miles, because a preferred peering relationship or a manually set Local Preference made a different path "better" in BGP's view.

This is why anycast tuning is a craft: operators use BGP communities and Local Preference to steer traffic toward the locations they want, rather than assuming the network will always pick the geographically closest one. It usually does — but "usually" is a routing decision, not a guarantee.

For a deeper look at how those path decisions are made, read BGP Basics. To see what the routing table actually looks like from different parts of the world, try a looking glass — a public BGP route viewer that shows how your prefix is seen from other networks.


How to Deploy Anycast Yourself

If you want to run your own anycast service — not just consume someone else's — here's the recipe:

  1. Get an ASN and a prefix. Obtain your own ASN and an IPv6 prefix (and IPv4 if budget allows). IPv6 is the pragmatic choice for new deployments — abundant address space and no /24 minimum requirement.
  2. Stand up identical instances. Deploy the same service in each location you want to serve. They must be functionally identical — any instance must be able to handle any request.
  3. Run BGP at each site. Advertise the same prefix from every location. Each site peers with upstream providers or an IXP, announcing the prefix as originating from your ASN.
  4. Monitor per-location health. If a site goes down, you must stop advertising the prefix from that location — otherwise traffic blackholes to a dead server. Automate this: health check fails → withdraw BGP announcement.
  5. Tune with BGP communities. Use Local Preference and communities to steer traffic toward preferred locations and away from congested ones.
  6. Let routing do the rest. Once BGP is advertising from all sites, the Internet's routing table handles distribution. No global load balancer needed.

For the bigger picture on how networks interconnect to make anycast possible, read Transit vs Peering and What Is an Internet Exchange.


FAQ

Is anycast the same as a load balancer?

No. A load balancer is an explicit device that inspects traffic and decides where to send it. Anycast has no such device — BGP path selection determines which instance receives each packet, based on routing topology. They're often combined: anycast gets the user to the nearest region, then a local load balancer distributes across servers within that region.

How is anycast different from GeoDNS?

GeoDNS returns different IP addresses based on the user's geographic location — a user in Europe gets a European IP, a user in Asia gets an Asian IP. Anycast uses the same IP everywhere and lets BGP routing decide. GeoDNS gives you explicit control over which users go where; anycast gives you automatic routing with less configuration. Many large deployments use both: anycast for the DNS servers themselves, GeoDNS for steering between anycasted service IPs.

Can anycast route to the fastest location, not just the nearest?

Standard anycast routes by BGP path selection (commonly AS-path length), which correlates with topological nearness but not necessarily the fastest path in terms of latency or throughput. Advanced setups use BGP communities, Local Preference tuning, or selective prefix advertisement to steer traffic more precisely — but it's tuning, not a built-in feature.

Does anycast work with IPv4 and IPv6?

Yes. Anycast is a routing concept independent of IP version. Most modern anycast deployments are dual-stack. That said, IPv6 is better suited to anycast because address space is abundant and there's no /24 minimum prefix length requirement.

Why don't all services use anycast?

Stateful applications — anything where a user's session lives on a specific server — don't fit anycast cleanly. If a BGP shift mid-session sends your packets to a different instance that doesn't have your session state, the connection breaks. Anycast shines for stateless, latency-sensitive, high-availability services. For stateful workloads, other architectures (GeoDNS + regional load balancers, or anycast for the front door only) are more appropriate.

Do I need my own ASN to use anycast?

To deploy your own anycast service, yes — you must advertise your own prefix via BGP from multiple locations, which requires an ASN. You can also consume someone else's anycast without owning one: every time you use a CDN, query a public DNS resolver, or sit behind a DDoS protection service, you're benefiting from anycast deployed by someone else.

How is anycast related to RPKI?

RPKI (Resource Public Key Infrastructure) secures BGP route advertisements by cryptographically verifying that the ASN advertising a prefix is authorized to do so. If you deploy anycast, you're advertising the same prefix from multiple locations — RPKI ensures those advertisements aren't hijacked by someone else. Anycast and RPKI are complementary: anycast distributes your service, RPKI protects the routes that make distribution work.


Conclusion

Anycast doesn't change how packets are sent. It changes where the Internet decides to send them. By advertising the same prefix from many locations, one IP address can exist in many places at once — while every user reaches a nearby instance automatically, with no special packets, no new protocol, and no global load balancer.

That simplicity is why anycast underpins the Internet's most critical and most attacked infrastructure: the DNS root server system, the largest CDNs, modern DDoS mitigation, and increasingly, the AI inference workloads that need GPU compute close to users. It's a routing trick, not a new protocol — and that's exactly why it scales.

Anycast is also a forcing function. Deploying it pushes you to think about your infrastructure in terms of prefixes, ASNs, BGP peering, and routing policy — the same primitives that make the Internet work at every level. Whether you deploy your own or consume it through a CDN, anycast is one of the few architectural patterns that genuinely makes the Internet feel local, everywhere, all at once.


Key Takeaways

  • Anycast advertises the same prefix from many locations; BGP path selection routes each user to the nearest instance automatically.
  • It's a routing trick, not a packet-format change — no new protocol, no new headers.
  • DNS roots, CDNs, and DDoS mitigation all depend on anycast for speed and resilience.
  • Emerging AI inference workloads are adopting anycast to place GPU compute close to users without client-side configuration.
  • Deploying your own anycast requires an ASN, a prefix, multi-site BGP connectivity, and health-check-driven route withdrawal.
  • Anycast works best for stateless services; it pairs naturally with RPKI for route security and IPv6 for abundant address space.

Continue Reading

Ready to get your own ASN?

Full RIPE NCC LIR sponsorship — ASN + /48 IPv6, one flat fee. RIPE NCC compliant, UK-based LIR.

See Pricing →