What is Subnet in Azure: Simple Explanation and Example
subnet is a smaller network segment within a virtual network (VNet) that helps organize and secure resources. It divides the VNet's IP address range into manageable parts, allowing better control of traffic and resource grouping.How It Works
Think of a virtual network (VNet) in Azure as a large neighborhood. A subnet is like a street within that neighborhood where houses (resources) are grouped together. This grouping helps organize resources logically and controls how they communicate with each other and the outside world.
Each subnet has its own range of IP addresses, carved out from the larger VNet's address space. This is similar to how a street has a range of house numbers. By dividing the network this way, Azure can manage traffic flow, apply security rules, and isolate resources to improve performance and safety.
Example
This example shows how to create a virtual network with a subnet using Azure CLI. It sets up a VNet with an address space and a subnet with its own smaller address range.
az network vnet create --resource-group MyResourceGroup --name MyVNet --address-prefixes 10.0.0.0/16 --subnet-name MySubnet --subnet-prefix 10.0.1.0/24
When to Use
Use subnets in Azure when you want to organize resources by function, security level, or environment. For example, you might place web servers in one subnet and databases in another to control traffic between them.
Subnets also help apply network security groups (NSGs) to control access and protect resources. They are essential when designing scalable, secure cloud architectures that separate workloads and manage traffic efficiently.
Key Points
- A subnet divides a virtual network into smaller address ranges.
- It helps organize and secure Azure resources.
- Each subnet has its own IP address range within the VNet.
- Subnets enable applying security rules and controlling traffic.