1. Gyanastra
  2. Computer Networks
  3. VLSM
  4. Subnet Masks for Variable-Length Subnets
Free lesson, no account needed 4 min read 44 practice questions after it
Asked in past papers5 times
  • GATE CSE2003
  • ISRO2009
  • UGC NET201320062005

Computer Networks · VLSM

Subnet Masks for Variable-Length Subnets

Overview

A subnet mask is a 32-bit value that marks which bits of an address belong to the network id and subnet id (all 1s) and which belong to the host id (all 0s).
In VLSM, subnets of different sizes use different numbers of subnet id bits, so each subnet gets its own mask. Deriving these masks correctly is what allows a single network to be divided into variable-length subnets.

Key concepts

  • Subnet mask: a 32-bit value with all 1s in the network id part and the subnet id part, and all 0s in the host id part.
  • The number of 1s in the mask equals (network id bits + subnet id bits); the number of 0s equals the host id bits.
  • For a network whose network id part is 24 bits, the mask always starts with 24 ones, i.e. 255.255.255; only the last octet changes with the subnet id bits.
  • Networks of the same size get the same subnet mask; networks of different sizes get different subnet masks — this is what makes the masking variable-length (VLSM).

How it works

  1. Write 24 ones for the network id part → 255.255.255.
  2. Write 1s for the number of subnet id bits chosen for that subnet.
  3. Fill the remaining host id bits with 0s.
  4. Convert the last octet to decimal.

Formulas

subnet mask=1…1⏟network id bits  1…1⏟subnet id bits  0…0⏟host id bits\text{subnet mask} = \underbrace{1\ldots1}_{\text{network id bits}}\;\underbrace{1\ldots1}_{\text{subnet id bits}}\;\underbrace{0\ldots0}_{\text{host id bits}}

  • number of 1s = network id bits + subnet id bits
  • number of 0s = host id bits

Worked examples

Deriving masks for three subnets of a /24 network:

SubnetNetwork id bitsSubnet id bitsHost id bitsSubnet id bits as binaryMask (last octet)Subnet mask
Subnet 124171 0000000128255.255.255.128
Subnet 2242611 000000192255.255.255.192
Subnet 3242611 000000192255.255.255.192
  • Subnet 1 (1 subnet id bit, 7 host id bits): 24 ones → 255.255.255; 1 subnet id bit set to 1 and the remaining 7 bits 0 → binary 10000000 = 128 → mask 255.255.255.128.
  • Subnet 2 (2 subnet id bits, 6 host id bits): 24 ones → 255.255.255; 2 subnet id bits set to 1 and the remaining 6 bits 0 → binary 11000000 = 192 → mask 255.255.255.192.
  • Subnet 3 (2 subnet id bits, 6 host id bits): same structure as Subnet 2 (24 network bits + 2 subnet bits) → mask 255.255.255.192.

Comparison

CaseSubnet sizeSubnet id bitsHost id bitsSubnet mask
Subnet 1different (larger)17255.255.255.128
Subnet 2same as Subnet 326255.255.255.192
Subnet 3same as Subnet 226255.255.255.192

Revision summary

  • Subnet mask = all 1s in network id + subnet id parts, all 0s in host id part.
  • For a /24 base network the mask always begins 255.255.255; only the last octet changes.
  • 1 subnet id bit → last octet 128; 2 subnet id bits → last octet 192.
  • Same-sized subnets → same mask; different-sized subnets → different masks (the basis of VLSM).
  • To find a mask: count the subnet id bits, set them to 1, set all host id bits to 0, then convert to decimal.

Previous-year exam insights

  • For an IPv4 prefix /n, the mask has n leading 1 bits and 32−n trailing 0 bits;
    the number of addresses in the subnet is 232−n2^{32−n}, and normally usable host addresses = 232−n−22^{32-n} - 2 because the network address and directed broadcast address are reserved. /31 and /32 are special exceptions.
  • VLSM requires a classless routing protocol that carries the subnet mask in routing updates, such as OSPF, EIGRP, RIPv2 or BGP; classful protocols such as RIPv1 and IGRP cannot support VLSM.
  • When allocating VLSM subnets, assign larger subnets before smaller ones and place each subnet on a block boundary equal to its size 2host bits2^{\text{host bits}}; otherwise smaller subnets may not fit or align correctly.
  • The network address of an interface is obtained by bitwise AND of the IP address and its subnet mask; the directed broadcast address has all host bits set to 1, and usable host addresses range from network address + 1 to broadcast address − 1.
  • For a mask octet value m in the interesting octet, the block size is 256 − m, and subnet network addresses in that octet occur at multiples of the block size.
  • In classless/VLSM addressing, the all-zero subnet and the all-ones subnet are usable; the old classful rule forbidding them does not apply.
Pages 1–2 of 2