Prepare and test your skills

Prepare and test your skills

Subnet expansion in Google Cloud is the process of increasing the number of available IP addresses in an existing subnet. A Virtual Private Cloud (VPC) (opens in a new tab) network is a global resource that holds regional subnets, and each subnet (opens in a new tab) holds a primary IPv4 range for its region. Expansion keeps the subnet in the same region and grows its primary IPv4 range so more virtual machine (VM) instances, load balancers, and other regional resources can receive addresses from it.
Primary IPv4 expansion grows a subnet by changing its subnet mask to a smaller prefix length, which creates a larger address block. The subnet keeps its existing addresses and adds new addresses around them, so current VMs and other resources keep their assigned IPs. The operation can take several minutes to complete, and traffic within the subnet is not interrupted during expansion. After expansion, other configurations that assumed the old range, such as firewall rules, routes, or address reservations, might need to be updated to recognize the larger range.
The requirements for subnet expansion define when a larger primary IPv4 range is allowed and when it is blocked. The proposed new range must follow the IPv4 subnet range limitations for VPC networks, including using a valid CIDR block that does not overlap another primary or secondary range in the same VPC network. Expansion moves in one direction only, from a longer prefix to a shorter prefix, and does not support shrinking a subnet to a smaller range.
/16.The /16 limit exists because broader auto mode ranges would conflict with the primary IPv4 ranges of the other automatically created subnets in other regions. Because all subnets in a VPC network must use unique ranges, planning must confirm that free address space exists next to the current range before requesting expansion.
Exam tip: A smaller prefix number means a larger subnet — expansion changes the mask to a smaller number, and auto mode subnets cannot go broader than /16.
Regional scope controls where subnet expansion helps and what it affects. The expanded addresses are available only in the subnet's own region, so the expansion helps resources that select that region and that subnet, such as VMs created in a zone whose parent region contains the subnet. Resources in other regions continue to use their own regional subnets and do not gain addresses from this change. Existing IP usage in the subnet is preserved, which avoids renumbering, but teams should review dependencies on both sides of the change, including the subnet that provides the addresses and the VMs, internal load balancers, alias IP ranges, and forwarding rules that consume them.
CIDR range planning for subnet expansion is the process of choosing a larger primary IPv4 range that contains the existing subnet range and provides more usable addresses. In a Virtual Private Cloud (VPC) (opens in a new tab) network, a subnet is a regional resource that defines the IPv4 addresses available in one region. Expansion is done by modifying the subnet mask to a smaller prefix length, so the new CIDR block preserves the original boundaries while extending outward to cover additional addresses.
CIDR block sizing determines how many IPv4 addresses a subnet can assign to resources in its region. A smaller prefix number creates a larger block with more addresses, while a larger prefix number creates a smaller block with fewer addresses. Every primary IPv4 subnet range reserves four unusable IP addresses, so the usable capacity is always four less than the total block size. The primary range supplies addresses for VM instances, internal load balancers, and internal protocol forwarding (opens in a new tab), so growth in those resources directly drives the need for expansion.
A planned expanded range is a new CIDR block that keeps all existing subnet addresses and adds contiguous space around them by using a smaller prefix length. The proposed range must be a unique valid CIDR block that does not overlap the primary or secondary ranges of any other subnet in the same VPC network. Subnets in a VPC network do not need to form one predefined contiguous block, but the expanded block must still follow IPv4 subnet range limitations.
A set diagram showing expanded CIDR 10.1.0.0/20 containing original 10.1.2.0/24 inside a VPC, kept separate from other primary and secondary ranges, with proxy-only and /16 limits noted.
/16.Auto mode VPC networks create subnets that fit inside the 10.128.0.0/9 CIDR block, so any prefix broader than /16 would conflict with the primary ranges of the other automatically created subnets. Planning must therefore check neighboring subnet ranges in the same VPC network before choosing the new prefix length.
Exam tip: A smaller prefix number means a larger subnet — expansion moves from a longer prefix toward a shorter one, but never broader than /16 for auto mode subnets.
Expanded addresses become part of the subnet primary IPv4 range and inherit the existing VPC routing behavior for internal addresses. VPC networks, including their routes and firewall rules, are global resources, while subnets are regional resources that define where regional internal IPv4 addresses are advertised. Routes define paths for packets leaving instances, and regional internal IPv4 addresses from primary and secondary ranges are advertised within the VPC network for VM-to-VM and service communication.
| Range type | Address role | Used by |
|---|---|---|
| Primary IPv4 range | Main subnet addresses for regional workloads | VM instances, internal load balancers, internal protocol forwarding, and alias IP ranges |
| Secondary IPv4 range | Additional subnet addresses for alias use only | Alias IP ranges only |
Expansion of the primary IPv4 range can take several minutes to complete, and traffic within the subnet is not interrupted during that time. After expansion, other configurations that assumed the old IP address range may need to be modified, because firewalls, routes, and peered systems outside the subnet do not automatically update to recognize the new addresses.
Subnet expansion using GCP tools is the process of giving an existing subnet more usable IP addresses inside its Virtual Private Cloud (VPC) network. A VPC network is a global resource that contains regional subnets (opens in a new tab), and each subnet defines the IPv4 and optionally IPv6 ranges that resources such as virtual machine (VM) instances can use. Expansion is done by enlarging the primary IPv4 range or by adding a secondary IPv4 range, using the Google Cloud console, gcloud CLI, or API-based automation.
Primary IPv4 range expansion increases the size of a subnet's main IPv4 block by changing its subnet mask to a smaller prefix length. A smaller prefix number means a larger address block, so the subnet can assign internal IPv4 addresses to more VMs, forwarding rules, and other regional resources. The proposed new range must follow the IPv4 subnet range limitations for the VPC network (opens in a new tab) and must not overlap or conflict with other subnet ranges in the same network. After expansion, other configurations that assume the old range, such as firewall rules, routes, Cloud NAT, or reserved addresses, might need to be updated to recognize the larger range.
Subnet expansion rules prevent address conflicts by limiting which subnets and ranges can change. When expanding an automatically created subnet in an auto mode VPC network, or in a custom mode network that was previously auto mode, the broadest prefix allowed is /16. Any prefix broader than /16 would conflict with the primary IPv4 ranges of the other automatically created subnets. Subnets used exclusively for load balancer proxies, called proxy-only subnets, cannot be expanded.
Secondary IPv4 ranges follow a related lifecycle rule for safe IP allocation sequencing. A new secondary range can be added to a subnet to provide additional addresses for services such as containers, and any secondary range can be removed only as long as no resources are using IP addresses in it. This dependency means the workflow depends on the resources in the subnet: the subnet depends on its address ranges being free before a range can be removed.
Subnet expansion execution uses three peer management paths that all act on the same regional subnet object in a VPC network. The console path uses the VPC networks page, where all networks and subnets in a project appear in a hierarchical view with subnets shown as entries within networks. The gcloud CLI path uses gcloud compute networks subnets update commands to modify address ranges for a named subnet in a region. The API path uses PATCH requests to the subnetworks.patch method, which carries the updated range data and the subnet fingerprint.
For secondary IPv4 ranges, the gcloud and API forms are explicit. To add a secondary range, traffic flows from the operator command to the subnet object, which then owns both the primary range and the named secondary range:
gcloud compute networks subnets update SUBNET --region=REGION --add-secondary-ranges=SECONDARY_RANGE_NAME=SECONDARY_RANGE
To remove a secondary range, the command flows from the operator to the same subnet object, but only after all using resources have been removed:
gcloud compute networks subnets update SUBNET --region=REGION --remove-secondary-ranges=SECONDARY_RANGE_NAME
The API equivalent sends a PATCH request to https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET with a secondaryIpRanges list and the current fingerprint of the subnet. Infrastructure-as-code tools use this same API model, so the declared range names and CIDR blocks in code must match the allowed IPv4 ranges and sequencing rules.
| Expansion type | What changes on the subnet | Key constraint |
|---|---|---|
| Primary IPv4 range | Existing primary block becomes larger through a smaller prefix length | New range must meet IPv4 range limitations; auto-created subnets cannot go broader than /16; proxy-only subnets cannot be expanded |
| Secondary IPv4 range | New named secondary block is added alongside the primary block | New range must use a valid IPv4 range; an existing secondary range can be removed only when no resources use it |
Operational safety for subnet expansion centers on disruption avoidance and dependent configuration alignment. Expanding the primary IPv4 range of a subnet can take several minutes to complete, and during expansion traffic within the subnet is not interrupted. The longer operation time means operators should wait for the expansion to reach its completed state before creating large numbers of new resources or changing dependent firewall, routing, or address-reservation policies.
Network governance for subnet expansion is controlled by Identity and Access Management (IAM) and by VPC network ownership boundaries. Permission to create and modify a subnet requires the Compute Network Admin (roles/compute.networkAdmin) IAM role on the project, which can also be granted through custom roles or other predefined roles. In a Shared VPC model, the VPC network lives in a common host project while authorized principals from other projects use its subnets, so expansion in the host project affects service projects on the other side of that project boundary. Converting an auto mode network to custom mode is one-way and preserves all subnets, which gives an organization stable control over future expansion without changing existing subnet names or ranges.
Exam tip: Expansion makes the prefix length smaller, auto-created subnets stop at /16, proxy-only subnets cannot be expanded, and in-subnet traffic is not interrupted during expansion.
/16, and proxy-only subnets cannot be expanded.Expanding the primary IPv4 range grows the subnet by changing to a smaller prefix length while preserving all existing IP addresses and adding new addresses around them. The operation can take several minutes to complete and traffic within the subnet is not interrupted during expansion. After expansion, firewall rules, routes, or address reservations that assumed the old range might need to be updated to recognize the larger range.
The new range must be a valid CIDR block that contains the original range by moving from a longer prefix to a shorter prefix and must not overlap any other primary or secondary range in the same Virtual Private Cloud (VPC) network. Expansion only grows a subnet and does not support shrinking to a smaller range. An automatically created subnet in an auto mode network, or in a custom mode network that was previously auto mode, cannot expand broader than /16, and a proxy-only subnet used exclusively for load balancer proxies cannot be expanded.
No, expanded addresses are available only in the subnet's own region. The expansion helps resources that select that region and that subnet, such as virtual machine (VM) instances created in a zone whose parent region contains the subnet, while resources in other regions continue to use their own regional subnets.
Your organization operates a custom mode VPC network in Google Cloud. A production subnet named prod-subnet located in the us-east1 region has an existing primary CIDR range of 10.2.0.0/24. Due to application scaling, the subnet is running out of available private IP addresses.
You need to expand the subnet capacity to a /20 prefix length to accommodate new Compute Engine virtual machines without causing service disruption or restarting existing instances.
Which command should you execute?
gcloud compute networks subnets update prod-subnet --region=us-east1 --add-secondary-ranges=prod-subnet-secondary=10.2.0.0/20
gcloud compute networks subnets delete prod-subnet --region=us-east1 followed by gcloud compute networks subnets create prod-subnet --region=us-east1 --range=10.2.0.0/20
gcloud compute networks subnets expand-ip-range prod-subnet --region=us-east1 --prefix-length=20
gcloud compute networks subnets update prod-subnet --region=us-east1 --range=10.2.0.0/20
Last updated