Lesson 14 — Virtual Networks & Subnets

Domain 4 — Networking AZ-104: 15–20% ~35 min Prereq: Lessons 01–13

Why You Need to Understand This First

Every Azure workload runs inside a Virtual Network, or connects through one. VNets are the foundational networking primitive — they determine how VMs talk to each other, how resources connect to the internet, how traffic is inspected, and where PaaS services are reachable. Without a solid understanding of VNet structure, address spaces, subnets, and routing, every subsequent networking topic (NSGs, peering, private endpoints, VPN gateways) will feel arbitrary.

On the AZ-104 exam, networking accounts for 15–20% of questions. Most of these questions assume you can reason through IP addressing, route precedence, and subnet sizing without hesitation. This lesson gives you that foundation.

VNet Fundamentals

An Azure Virtual Network (VNet) is a logically isolated network in the Azure cloud. Resources deployed into a VNet communicate with each other using private IP addresses by default — no public internet exposure, no routing through Microsoft's external network.

  • Region-specific: a VNet always lives in exactly one Azure region. You cannot stretch a single VNet across regions. For cross-region connectivity you use VNet Peering or a VPN Gateway.
  • Availability zones: a single VNet can span all availability zones within its region. A subnet in that VNet also spans all AZs — you do not need separate subnets per AZ.
  • No cost for the VNet itself: creating a VNet is free. You pay for associated resources (public IPs, gateways, firewalls) not for the VNet or subnets.
  • Soft isolation boundary: resources in different VNets cannot communicate by default, even within the same subscription. Peering or gateways must be explicitly configured.
Azure Region (e.g. East US) └─ VNet: 10.10.0.0/16 ├─ Subnet: 10.10.1.0/24 (WebTier) │ ├─ VM: 10.10.1.4 │ ├─ VM: 10.10.1.5 │ └─ VM: 10.10.1.6 ├─ Subnet: 10.10.2.0/24 (AppTier) │ ├─ VM: 10.10.2.4 │ └─ VM: 10.10.2.5 └─ Subnet: 10.10.3.0/28 (GatewaySubnet) └─ VPN Gateway NIC: 10.10.3.4
VNet ≠ Subscription boundary A single subscription can have up to 1,000 VNets per region. Multiple VNets in the same subscription do not automatically communicate — each is isolated. You must explicitly configure peering, VPN, or ExpressRoute connections.

Address Space & CIDR Planning

When you create a VNet, you assign one or more address spaces in CIDR notation. All subnets within the VNet must fall within these address spaces. You can add address spaces later, but you cannot remove an address space that contains active subnets.

RFC 1918 private ranges

Always use RFC 1918 private ranges for VNet address spaces. These ranges are not routable on the public internet:

RangeCIDRAddressesCommon Azure use
10.0.0.0/816,777,216Large enterprises — subdivided per region/spoke
172.16.0.0/121,048,576Medium environments
192.168.0.0/1665,536Small workloads / dev environments
Non-overlapping is non-negotiable If you plan to connect your VNet to on-premises via VPN or ExpressRoute, or peer it with other VNets, the address spaces must not overlap. Overlap means routing ambiguity — Azure will refuse to create the peering or gateway connection. Plan your address space before deploying anything into it. Changing it later requires deleting and recreating subnets.

Practical CIDR reference

CIDRTotal IPsAzure-usable IPsTypical use
/1665,53665,531Hub or large spoke VNet
/24256251Standard application subnet
/266459AzureFirewallSubnet minimum
/273227GatewaySubnet minimum (recommended)
/281611Small service subnet
/2983Absolute minimum — avoid in practice

Subnets & Azure Reserved Addresses

A subnet divides a VNet's address space into smaller segments. Every resource that requires network connectivity (VMs, load balancers, App Service Environments, etc.) must be deployed into a subnet.

The 5 reserved addresses per subnet

Azure reserves 5 IP addresses from every subnet. You cannot assign these to resources:

Reserved IPPurposeExample (/24 starting at 10.10.1.0)
First address (.0)Network address10.10.1.0
Second address (.1)Default gateway10.10.1.1
Third address (.2)DNS mapping (Azure DNS)10.10.1.2
Fourth address (.3)DNS mapping (Azure DNS)10.10.1.3
Last address (.255)Broadcast address10.10.1.255
Subnet sizing exam trap A /27 subnet has 32 IPs. Azure reserves 5, leaving 27 usable IPs for resources. A /29 has 8 IPs, reserves 5, leaving only 3 — this is the smallest possible subnet. For any production workload, use /28 (11 usable) as a minimum. When planning VM-dense subnets, remember that each VM NIC consumes one IP, plus any attached load balancer front-end IPs or private endpoints.

Subnet properties

  • Subnets span all availability zones within the VNet's region — you do not need to create per-AZ subnets.
  • A subnet cannot span multiple VNets or multiple regions.
  • You can add subnets to a VNet at any time without downtime to existing resources.
  • Subnets can optionally have an NSG associated (traffic filtering) and a Route Table associated (custom routing).

Service Delegation

Service delegation reserves a subnet exclusively for a specific Azure managed service. When you delegate a subnet to a service, that service gains the permission to configure the subnet and inject resources directly into it with private IPs from your address space.

Common service delegations

Delegation valueServiceNotes
Microsoft.Web/serverFarmsApp Service (VNet Integration)Outbound VNet integration for App Service Plans
Microsoft.Sql/managedInstancesSQL Managed InstanceRequires dedicated subnet; mandatory delegation
Microsoft.ContainerInstance/containerGroupsAzure Container InstancesACI with VNet injection
Microsoft.Databricks/workspacesAzure DatabricksRequires 2 delegated subnets (public + private)
Microsoft.NetApp/volumesAzure NetApp FilesDedicated subnet required
Delegation is exclusive Once a subnet is delegated to a service, you cannot deploy other resource types (VMs, other Azure services) into it. The subnet is reserved entirely for that service. Plan delegated subnets as purpose-built allocations — size them for the service's scale requirements, not for general use.

User Defined Routes (UDR) & Route Tables

Azure automatically creates system routes for every subnet: a route for the VNet address space (to keep intra-VNet traffic local), a default internet route (0.0.0.0/0 → Internet), and routes for any peered VNets or connected gateways. You can override these with User Defined Routes.

UDR next hop types

Next Hop TypeBehaviourWhen to use
VirtualNetworkRoutes within the VNet address spaceRarely overridden — system handles this
InternetSends traffic to the public internetExplicitly route traffic out via internet
VirtualApplianceForwards traffic to a specific private IP (NVA or Azure Firewall)Force internet traffic or spoke-to-spoke through a firewall
VirtualNetworkGatewayRoutes to VPN or ExpressRoute gatewayInjected automatically by gateway; rarely set manually
NoneDrops the traffic (black hole)Block specific destinations at the routing layer

Forced tunneling pattern

The most common UDR pattern in enterprise environments is forced tunneling through Azure Firewall:

Route Table: rt-spoke-webtier
  Route: 0.0.0.0/0  →  VirtualAppliance  →  10.10.0.4  (Azure Firewall private IP)
  Associated to: subnet-webtier, subnet-apptier

This overrides the default internet route, forcing all outbound internet traffic from those subnets through the Azure Firewall for inspection before it leaves the VNet.

Route Table association is per-subnet A route table must be explicitly associated with each subnet you want to affect. Creating a route table and adding routes does nothing until it is associated. Multiple subnets can share the same route table. A subnet can have at most one route table associated with it.
Longest prefix match wins When multiple routes match a destination, Azure selects the most specific route (longest prefix match). A /32 route to a specific host IP overrides a /24 subnet route, which overrides a /0 default route. User-defined routes override system routes for the same prefix.

Azure Firewall (NVA Reference Point)

Azure Firewall is a managed, stateful, cloud-native firewall-as-a-service. For the AZ-104 exam you do not need deep Firewall configuration knowledge — but you must understand it as the canonical NVA (Network Virtual Appliance) target for UDRs and the hub-spoke pattern.

Key deployment facts

  • Deployed into a dedicated subnet named AzureFirewallSubnet — this exact name is required.
  • Minimum subnet size: /26 (64 IPs). Microsoft recommends /26 to accommodate scaling.
  • Requires a Standard or Premium tier public IP (Standard SKU, static allocation).
  • Stateful — return traffic is automatically allowed; no need for reverse rules.

Rule types (know the names)

Rule typeLayerWhat it matches
Network rulesL4Source IP, destination IP, protocol, port
Application rulesL7FQDNs, URLs, HTTP/S traffic categories
DNAT rulesL4Inbound port forwarding from public IP to private backend
Exam context for Azure Firewall AZ-104 questions on Azure Firewall typically centre on: (1) what subnet name and minimum size is required, (2) how UDRs direct traffic to the Firewall's private IP, and (3) the forced tunneling pattern. Deep Firewall policy configuration belongs to AZ-700 (Network Engineer).

DNS in Virtual Networks

DNS configuration in a VNet determines how all VMs in that VNet resolve hostnames. There are two modes: Azure-provided DNS and custom DNS servers.

Azure-provided DNS (default)

By default, VMs in a VNet use Azure's recursive DNS resolver at 168.63.129.16. This virtual IP provides:

  • Resolution of Azure-provided internal hostnames (e.g. vm-name.internal.cloudapp.net)
  • Resolution of names in Private DNS Zones that are linked to the VNet
  • Forwarding of all other queries to Azure's public DNS resolvers

Custom DNS servers

Set custom DNS server IPs at the VNet level (Settings → DNS servers). This overrides 168.63.129.16 for all VMs in the VNet. Use cases:

  • Hybrid DNS: forward queries for on-premises domain (corp.contoso.com) to an on-premises DNS server
  • Custom resolver: an Azure DNS Private Resolver or Windows Server DNS in the VNet
  • Split-brain DNS: different resolution for internal vs external callers
VM restart required after DNS change VMs receive their DNS server setting via DHCP at startup. If you change the DNS servers on a VNet, existing VMs do not pick up the change until they are stopped (deallocated) and started again. A reboot is not sufficient — the VM must be deallocated to receive a fresh DHCP lease. This is a frequent exam question.
Do not point VNet DNS directly at 168.63.129.16 as a custom server If you configure custom DNS and need Azure DNS resolution (for Private DNS Zones), either use Azure DNS Private Resolver or add a forwarder in your custom DNS server that forwards Azure-specific zones to 168.63.129.16. Pointing directly at 168.63.129.16 in the custom DNS field actually works, but is not the recommended pattern for complex hybrid environments.

Public IP Addresses

Azure Public IP addresses attach to resources (VM NICs, Load Balancers, Application Gateways, Bastion, Firewall) to provide inbound and/or outbound internet connectivity. Public IPs come in two SKUs and two allocation methods.

Basic SKU vs Standard SKU

FeatureBasic SKUStandard SKU
Zone redundancyNot zone-redundantZone-redundant by default
Default allocationDynamic (or static)Static only
Inbound security (default)Open — inbound allowed by defaultSecure — all inbound blocked unless NSG permits
Load Balancer compatibilityBasic Load Balancer onlyStandard Load Balancer required
App Gateway v2Not supportedRequired
AvailabilityRetiring November 2025Current; use for all new deployments
Routing preferenceMicrosoft network onlyMicrosoft network or Internet routing
Basic SKU is retiring Basic Public IPs are being retired. For the AZ-104 exam you need to know the differences above, especially: Standard SKU is secure by default (all inbound blocked), requires an NSG to allow traffic, uses static allocation, and is required for Standard Load Balancer and Application Gateway v2. Basic SKU is open by default. Always use Standard for any new resource.

Allocation methods

  • Dynamic allocation: IP is assigned when the resource starts and released when it is stopped/deallocated. The IP address can change between stop-start cycles. Basic SKU supports dynamic; Standard SKU is always static.
  • Static allocation: IP is assigned when you create the public IP resource and held until you explicitly delete it — does not change on stop/start. Standard SKU is always static. Required for DNS A records, TLS certificates tied to IP, and scenarios needing a predictable inbound address.

Enterprise Address Space Planning

Ad hoc IP address planning is one of the most painful technical debts in Azure environments. Retrofitting overlapping address spaces after deployment can require destroying and rebuilding entire VNets. Get this right at the start.

Planning principles

  • Reserve large blocks per region: allocate at least a /16 per region-spoke combination. This gives you 65,536 IPs to subdivide into subnets without running out.
  • Never use 10.0.0.0/8 as one allocation: do not assign the entire /8 to a single VNet. Divide it into /16 blocks, one per region or business unit (e.g. 10.10.0.0/16 for East US, 10.20.0.0/16 for West Europe, 10.30.0.0/16 for dev, etc.).
  • Document on-premises ranges first: collect all on-premises CIDR blocks before designing Azure ranges. Non-overlap with on-premises is mandatory for any hybrid scenario.
  • Account for peered VNets: peered VNets cannot have overlapping address spaces. In a hub-spoke model, all spoke /16s must be unique across the entire estate.
  • Use IPAM tooling: Azure Virtual Network Manager includes an IPAM feature. Third-party tools (Infoblox, phpIPAM, NetBox) are also common.

Example enterprise allocation

10.0.0.0/8  — Reserved for all Azure

  10.10.0.0/16  — East US: Hub VNet
    10.10.0.0/24  — AzureFirewallSubnet
    10.10.1.0/24  — GatewaySubnet
    10.10.2.0/24  — ManagementSubnet

  10.20.0.0/16  — East US: Spoke-Prod
    10.20.1.0/24  — WebTier
    10.20.2.0/24  — AppTier
    10.20.3.0/24  — DataTier

  10.30.0.0/16  — East US: Spoke-Dev
    (subdivide as needed)

  10.100.0.0/16  — West Europe: Hub VNet
  10.110.0.0/16  — West Europe: Spoke-Prod

172.16.0.0/12 — Reserved for on-premises
Reserved Azure service ranges Azure uses certain IP ranges internally. Do not use 169.254.0.0/16 (link-local), 168.63.0.0/16 (Azure platform), or 100.64.0.0/10 (CGNAT shared space) in your VNet address spaces. These will cause routing conflicts with Azure internal services.

Check Your Understanding

Click any option to see immediate feedback. Answers reflect real Azure behaviour, not documentation theory.

1. You create a /27 subnet within a VNet. How many IP addresses are available for virtual machines and other resources?

A /27 contains 32 IPs. Azure always reserves 5: the network address (.0), default gateway (.1), two DNS addresses (.2 and .3), and broadcast (last IP). That leaves 32 − 5 = 27 usable IPs for resources. This arithmetic is essential for subnet sizing questions.

2. You need all outbound internet traffic from a subnet to pass through Azure Firewall for inspection. What is the correct configuration?

The correct approach is to create a route table with a default route (0.0.0.0/0) whose next hop type is VirtualAppliance and next hop IP is the Azure Firewall's private IP address. Associate this route table with every subnet you want to force through the Firewall. This overrides the system's default internet route for that subnet. NSGs are Layer 4 stateful filters, not routing devices — they cannot redirect traffic to another appliance.

3. A subnet is delegated to Microsoft.Sql/managedInstances. What restrictions apply to that subnet?

Service delegation is exclusive — a delegated subnet is reserved entirely for the designated service. No other resource types can be deployed into a subnet delegated to Microsoft.Sql/managedInstances. This is enforced at the control plane level, not just advisory. SQL Managed Instance also imposes additional requirements: no NSG rules blocking specific ports, no UDRs to certain prefixes, and a dedicated /27 or larger subnet.

4. You need a public IP address for a new Standard Load Balancer and require the IP to be zone-redundant. Which public IP configuration meets these requirements?

Standard Load Balancer requires a Standard SKU public IP — Basic SKU is incompatible. Standard SKU public IPs are always statically allocated and zone-redundant by default. Standard SKU is also secure by default (all inbound blocked until NSG allows it), whereas Basic SKU allows inbound by default. Basic SKU is being retired and should not be used for any new resource.

5. You change the DNS server setting on a VNet from Azure default to a custom DNS server at 10.10.2.4. When will existing running VMs start using the new DNS server?

VMs receive DNS server configuration through DHCP at network interface initialisation — which happens when the VM boots after being allocated. An OS-level reboot does not deallocate the VM, so the NIC retains its existing DHCP configuration. The VM must be stopped (deallocated) via the Azure portal or CLI, then started again. "Restart" inside the OS is insufficient.

6. What is the minimum subnet size in Azure, and how many IPs are usable for resources in that subnet?

The absolute minimum subnet size Azure supports is /29 (8 IPs). After Azure reserves 5 addresses, only 3 IPs remain for resources. While /29 is technically valid, it is impractical — even adding a second VM exhausts the subnet. Use /28 (16 IPs, 11 usable) as a practical minimum for most workloads. Note that GatewaySubnet requires at least /27 and AzureFirewallSubnet requires /26.
Primary source for this lesson Azure Virtual Network — Overview (Microsoft Learn)

Read the full overview article and the linked subnet planning guide. Pay particular attention to the reserved address section and the service delegation list — both are directly tested on AZ-104.

Questions for your teacher (the AI agent)
This lesson covered VNet structure, addressing, routing, and public IPs. Go deeper on any of these:
  • Walk me through designing a complete address space for a hub-spoke estate with 3 regions and 5 spoke VNets per region.
  • Explain the interaction between UDRs, system routes, and BGP routes — what happens when all three exist for the same prefix?
  • What are the specific NSG and UDR restrictions imposed on a SQL Managed Instance subnet?
  • How does Azure DNS Private Resolver fit into a hybrid DNS architecture, and when should it replace a custom DNS VM?
Coming up: Lesson 15 — Network Security Groups & Application Security Groups Now that you can build a VNet and route traffic, the next lesson covers how to control which traffic is allowed or denied — using NSGs for stateful Layer 4 filtering, service tags for managed IP ranges, and Application Security Groups for role-based rules that survive VM IP changes.