0
0
Azurecloud~10 mins

Subnets within a VNet in Azure - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Subnets within a VNet
Create Virtual Network (VNet)
Define Address Space for VNet
Create Subnet 1 with CIDR
Create Subnet 2 with CIDR
Assign Subnets to VNet
VNet with multiple subnets ready for resources
This flow shows how a virtual network is created first, then divided into smaller subnetworks (subnets) with their own address ranges inside the VNet.
Execution Sample
Azure
resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = "eastus"
  resource_group_name = "example-rg"
}

resource "azurerm_subnet" "subnet1" {
  name                 = "subnet1"
  resource_group_name  = "example-rg"
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.1.0/24"]
}

resource "azurerm_subnet" "subnet2" {
  name                 = "subnet2"
  resource_group_name  = "example-rg"
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
}
This code creates a virtual network with a large address space, then creates two subnets inside it with smaller address ranges.
Process Table
StepActionResource CreatedAddress SpaceSubnet CIDRResult
1Create VNetVirtual Network10.0.0.0/16N/AVNet created with large address space
2Create Subnet 1Subnet10.0.0.0/1610.0.1.0/24Subnet1 created inside VNet
3Create Subnet 2Subnet10.0.0.0/1610.0.2.0/24Subnet2 created inside VNet
4Assign SubnetsVNet with Subnets10.0.0.0/1610.0.1.0/24, 10.0.2.0/24VNet now contains two subnets
5EndN/AN/AN/ASetup complete, ready for resource deployment
💡 All subnets created within the VNet address space, no overlaps, deployment ready
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
VNet Address SpaceNone10.0.0.0/1610.0.0.0/1610.0.0.0/1610.0.0.0/16
Subnet1 CIDRNoneNone10.0.1.0/2410.0.1.0/2410.0.1.0/24
Subnet2 CIDRNoneNoneNone10.0.2.0/2410.0.2.0/24
Subnets AssignedNoneNoneSubnet1Subnet1, Subnet2Subnet1, Subnet2
Key Moments - 3 Insights
Why must subnet CIDRs be within the VNet address space?
Subnet CIDRs must fit inside the VNet address space to avoid IP conflicts and ensure all subnets belong to the same network, as shown in execution_table steps 1 to 4.
Can subnets overlap each other’s address ranges?
No, subnets cannot overlap. Each subnet must have a unique, non-overlapping CIDR block inside the VNet, as seen in steps 2 and 3 where subnets have distinct ranges.
What happens if you try to create a subnet outside the VNet address space?
The deployment will fail because Azure requires subnets to be inside the VNet’s address space, which is why step 4 confirms subnets are assigned only if they fit inside the VNet.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the CIDR of Subnet2?
A10.0.2.0/24
B10.0.1.0/24
C10.0.0.0/16
D192.168.1.0/24
💡 Hint
Check the 'Subnet CIDR' column at step 3 in the execution_table.
At which step are both subnets assigned to the VNet?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Subnets Assigned' variable in variable_tracker after each step.
If Subnet1 CIDR was changed to 10.0.2.0/24, what would happen?
AVNet address space would automatically expand
BSubnet1 and Subnet2 would overlap causing deployment failure
CSubnet1 would be created successfully with no issues
DSubnet2 would be deleted automatically
💡 Hint
Refer to key_moments about overlapping subnets and execution_table steps 2 and 3.
Concept Snapshot
Subnets within a VNet:
- Create a VNet with a large address space (e.g., 10.0.0.0/16)
- Define subnets with smaller CIDR blocks inside the VNet range
- Subnets must not overlap each other
- Assign subnets to the VNet before deploying resources
- Ensures organized IP allocation and network segmentation
Full Transcript
This lesson shows how to create a virtual network (VNet) in Azure and divide it into smaller parts called subnets. First, you create the VNet with a big address space like 10.0.0.0/16. Then you create subnets inside it with smaller address ranges like 10.0.1.0/24 and 10.0.2.0/24. Each subnet must fit inside the VNet's address space and cannot overlap with others. After creating subnets, they are assigned to the VNet. This setup allows you to organize your network and assign IP addresses properly for your cloud resources.