Advertise prefixes (2)
Last updated Oct 6, 2026
Onboard prefixes
You can bring your own public IP addresses to Cloudflare to use with Magic Transit. This is also known as bring your own IP (BYOIP). This process involves two distinct types of prefixes:
- IP prefixes: Each IP address block you bring to Cloudflare requires an IP prefix entry. The IP prefix includes the permission (Letter of Agency (LOA)) that allows Cloudflare to announce the network or its subnets. You can also define your optional Autonomous System Number (ASN) ↗︎ to be included in our advertised AS path.
- BGP prefixes: These control which prefixes Cloudflare announces from its global network. By default, each IP prefix has one matching BGP prefix. You can configure additional, more-specific BGP prefixes (subnets of the IP prefix), up to a maximum prefix length of
/24.
IP prefixes
Cloudflare measures the Magic Transit prefix count based on the number of BGP prefixes you define. Each prefix is billed separately, even if they overlap. For example, both a /16 and any /24 within it are counted individually. Onboarding a larger aggregate prefix does not automatically include its smaller subnets for announcement or billing purposes.
There is no billing limit on the accepted prefix sizes. However, only prefixes up to /24 are accepted for onboarding because longer prefixes (like /25, /26) are not globally routable.
Provide all IP prefixes you plan to onboard, along with the ASNs from which you will advertise them. When specifying prefixes, observe these guidelines:
- Prefixes must include at least 256 IP addresses (
/24in CIDR (Classless Inter-Domain Routing ↗︎) notation). If you do not meet the/24prefix length requirement, refer to Use a Cloudflare IP. - Internet Routing Registry entries and LOA must match the prefixes and originating prefixes you submit to Cloudflare.
- When using contiguous prefixes, specify aggregate prefixes where possible.
- When using Route Origin Authorizations (ROAs) to sign routes for resource public key infrastructure (RPKI) ↗︎, the prefix and originating ASN must match the onboarding submission.
- If you do not own an ASN, you can use the Cloudflare Customer ASN (AS13335).
Cloudflare ASN vs. your own ASN
As part of your IP prefix onboarding process, you need to decide which ASN Cloudflare will use to announce your prefixes. If you supply your own ASN, Cloudflare prepends the main Cloudflare ASN (AS13335) to the BGP AS_PATH. For example, if your ASN is AS64496, anyone directly peering with Cloudflare sees the path as 13335 64496.
If you do not have an ASN or do not want to bring your ASN to Cloudflare, you can use the Cloudflare Customer ASN (AS13335).
Note
For all future onboardings, you must use AS13335. If you already use Cloudflare's AS209242, you do not need to make changes and can continue using that ASN.
BGP prefixes
BGP prefixes represent the prefix that Cloudflare will announce through anycast from Cloudflare's global network. By default, there is always at least one BGP prefix that is identical to the onboarded IP prefix.
For example, if you onboard a /20 IP prefix to Magic Transit, it can only be announced as a /20 because there is only the default /20 BGP prefix. Smaller sub-prefixes (such as /24s) within that /20 cannot be announced individually unless they are configured as separate BGP prefixes.
BGP prefix advertisement control methods
Cloudflare offers multiple mechanisms to control the announcement and withdrawal of on-demand prefixes. Each method serves different deployment scenarios:
- Addressing API: Manually control prefix advertisements through API calls. Refer to Advertise or withdraw a BGP prefix.
- BGP peering with route reflectors: Control advertisements through BGP sessions to Cloudflare's globally distributed route reflectors, either over the Internet or over a CNI connection with Dataplane v1. Contact your Cloudflare account team if you need this option. Refer to BGP control with Cloudflare Route Reflectors.
- Network Flow: Automatically announce prefixes based on user-defined traffic thresholds observed in your network. Refer to Network Flow (formerly Magic Network Monitoring).
- BGP peering with Magic Transit network routing table: Automatically control prefix advertisements based on BGP routes learned through GRE and IPsec tunnels, or CNI with Dataplane v2 (closed beta). This method requires Unified Routing. Refer to BGP control to Magic Transit Virtual Network routing table.
Important
You should only use one control method per prefix at any given time. Mixing multiple control planes can lead to conflicting advertisement states, causing unpredictable routing behavior.
Manage BGP prefixes
Add a BGP prefix
Create a POST request to add a BGP prefix. For example:
Create BGP Prefixbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bgp/prefixes" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"cidr": "192.0.2.0/24"
}'
Advertise or withdraw a BGP prefix
Note
You can only advertise your prefix after running pre-flight checks with Cloudflare. If your prefix status is grayed out and shows a Withdrawn status, Cloudflare locks your prefix. Contact your account team to close the pre-flight checks phase and unlock your prefixes.
Currently, only the default BGP prefix (that matches the IP prefix) can be controlled through the Cloudflare dashboard.
- Go to the Routes page.
- From the IP prefixes tab, select the prefix you want to modify > Edit.
- From the Status drop-down menu, select Advertised or Withdrawn.
- (Optional) Edit the description for your prefix.
- Select Edit IP Prefix to save your changes.
Any configured BGP prefix can be controlled through the API using a PATCH request. For example:
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>Magic Transit Write</code>
- <code>IP Prefixes: Write</code>
- <code>IP Prefixes: BGP On Demand Write</code>
</details>
Update BGP Prefixbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bgp/prefixes/$BGP_PREFIX_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"on_demand": {
"advertised": true
}
}'
Warning: ISP route refresh delays may impact traffic
Announcing or withdrawing a prefix means Cloudflare will begin or stop advertising routes, impacting traffic flow to or from that IP range. Changes propagate across Cloudflare's global network almost instantly, typically taking effect within minutes. However, Cloudflare has no control over how quickly ISPs refresh their routes.
Refer to Safely withdraw a BYOIP prefix for more information on how to prevent blackholing during prefix withdrawals.
Delete an IP prefix
You can only delete a prefix with an Unapproved status. To delete prefixes with a different status, contact your administrator or account manager.
- Go to the Routes page.
- From the IP Prefixes tab, locate the prefix you want to modify and select Delete.
- Confirm your choice from the modal by selecting Delete.
Use the API to set AS prepends on a BGP prefix
Use the Addressing API to control the number of times Cloudflare prepends its Autonomous System Number (ASN) to a prefix. You can prepend AS13335 up to three times in the AS_PATH of BGP updates for your prefixes.
Caution
BGP has different mechanisms to control route priorities which are set by the peered network, not by Cloudflare. As such, this is a best-effort feature. Cloudflare cannot guarantee that peers will honor AS prepends on Cloudflare's transit and peering connections.
Refer to the following example for how to prepend AS13335 three times to a BGP prefix:
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>Magic Transit Write</code>
- <code>IP Prefixes: Write</code>
- <code>IP Prefixes: BGP On Demand Write</code>
</details>
Update BGP Prefixbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bgp/prefixes/$BGP_PREFIX_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"asn_prepend_count": 3
}'
AS prepending helps you gracefully transition traffic between network providers. By adding prepends to Cloudflare's advertisement, you make the route through Cloudflare less preferred for some Internet network providers. This allows you to simultaneously advertise the same prefix from an alternate provider with a shorter, more desirable AS_PATH. Advertising from both providers at once provides a smoother traffic migration and minimizes packet loss during a change of provider.
The "asn_prepend_count" parameter accepts values from 0 to 3. A higher value makes the route less preferred. You can also change this parameter using BGP. Refer to Use communities to set AS prepends on an anycast prefix.
When you use AS prepending to migrate traffic away from Magic Transit, the typical sequence of events is as follows:
- Initial state: Cloudflare advertises your prefix with the default priority (
"asn_prepend_count": 0). Cloudflare routes all traffic to your network through the Cloudflare global network. - Deprioritize Cloudflare: You update the prefix through the API to set an AS prepend count (for example,
"asn_prepend_count": 3). Cloudflare now advertises your prefix with a longerAS_PATH. External networks will update their BGP tables to recognize the Cloudflare path has the new, longerAS_PATH. - Introduce new provider: You begin advertising the same prefix from your alternate provider with a standard (shorter)
AS_PATH. - Final state: External networks now receive two advertisements: the prepended route through Cloudflare and the non-prepended route through your new provider. The external network will select a path based on its BGP policy rules.
Caution
Cloudflare's internal network enforces local preference for traffic delivery to Magic Transit, even if a more specific or shorter path route is available on the public Internet. Withdraw the prefix from Cloudflare to avoid delivery of Cloudflare-sourced traffic over Magic Transit. This preference is local to our internal network and does not impact the route decision process of other networks.
For example, if you have a CDN zone with a Magic Transit-protected origin that is part of a Cloudflare-advertised /22 prefix, and you later advertise a more specific /24 prefix route directly from your network, Cloudflare's servers will continue to route proxied CDN traffic to your Magic Transit network. The traffic will follow configured routes to your tunnel(s). This behavior is specific to Cloudflare services. Traffic from other sources will converge to the direct route as expected by BGP.
Safely withdraw a BYOIP prefix
Mitigating stuck BGP routes
When you prepare to remove traffic for a Bring Your Own IP (BYOIP) prefix from the Cloudflare edge, a direct BGP withdrawal action carries the risk of a stuck BGP route. This state occurs when a route becomes stuck in the Internet's Default-Free Zone (DFZ) ↗︎. Core routers that missed the withdrawal announcement continue forwarding traffic to a now-inactive next-hop (what is known as a blackhole). You can read more about this in our blog post BGP zombies and excessive path hunting ↗︎.
This risk is especially evident in the use case where the global routing table relies on more-specific to less-specific prefix routing fallback. Since this fallback mechanism is highly prone to route instability, Cloudflare recommends a multi-step draining process.
Multi-step BYOIP withdrawal process
When draining traffic, use the same prefix length on Cloudflare and on your ISP (Internet Service Provider), since matching prefix lengths gives the most effective and deterministic behavior.
The following steps outline the recommended multi-step draining process to achieve a clean traffic cutover and prevent blackholing.
