An IPv4 address is a 32-bit number that identifies an interface on a network, and subnetting is how you carve one address block into several smaller networks. The reason this topic feels hard is that people try to do it in decimal. Do it in binary, or with the block-size shortcut below, and it becomes pure arithmetic. This is one of the most reliably tested areas in Computer Networks, and it is entirely learnable.
Let us build it up from the address itself.
IPv4 address structure
An IPv4 address is 32 bits, written as four 8-bit octets in dotted decimal, for example 192.168.1.10. Each octet ranges from 0 to 255, because 8 bits hold values 0 to 2^8 − 1.
Every address splits into two parts: a network portion (which network this interface belongs to) and a host portion (which interface on that network). The boundary between them is set by the subnet mask. The mask is also 32 bits: a run of 1s marks the network portion, then a run of 0s marks the host portion. A mask of 255.255.255.0 is twenty-four 1s followed by eight 0s, so the first three octets are network and the last octet is host.
Classful addressing versus CIDR
Historically, the leading bits fixed the split into fixed classes:
Class A: first octet 1 to 126, default mask /8. Huge networks.
Class B: first octet 128 to 191, default mask /16.
Class C: first octet 192 to 223, default mask /24. Small networks.
Class D: 224 to 239, reserved for multicast.
Class E: 240 to 255, reserved for experiments.
Classful addressing wasted enormous ranges, so the modern scheme is CIDR (Classless Inter-Domain Routing). CIDR drops the classes and writes the mask length explicitly as a slash-prefix: 192.168.1.0/24 means the first 24 bits are the network. Any prefix length is allowed, which is what makes flexible subnetting possible. Also memorise the private ranges reserved by RFC 1918: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
The two numbers that run subnetting
For a prefix /n, only two formulas matter. If you borrow s bits from the host part to create subnets, and h host bits remain, then:
Number of subnets = 2^s
Usable hosts per subnet = 2^h − 2
The "− 2" is because the all-zeros host pattern is the network address and the all-ones host pattern is the broadcast address; neither can be assigned to a device. The block size (how far apart consecutive subnets sit) equals 256 minus the value of the last non-255 octet of the mask, and it is the fastest way to list subnets without touching binary.
A fully worked subnetting example
Problem. You are given the Class C block 192.168.1.0/24 and asked to split it into four equal subnets. Find the new mask, and for each subnet give the network address, the usable host range, and the broadcast address.
Step 1, borrow bits for the subnets. You need 4 subnets, and 2^s = 4 gives s = 2. Borrow 2 bits from the host part. The prefix grows from /24 to /26.
Step 2, write the new mask. /26 is twenty-six 1s: 255.255.255.192, because the last octet is 11000000, which is 192.
Step 3, hosts per subnet. With /26, host bits h = 32 − 26 = 6, so usable hosts = 2^6 − 2 = 62 per subnet.
Step 4, block size. 256 − 192 = 64. Subnets therefore start at multiples of 64 in the last octet: 0, 64, 128, 192.
Step 5, tabulate. For each subnet, the network address is the block start, the broadcast is one below the next block start, and the usable hosts sit strictly between them.
Subnet | Network address | Usable host range | Broadcast |
|---|---|---|---|
1 | 192.168.1.0/26 | .1 to .62 | 192.168.1.63 |
2 | 192.168.1.64/26 | .65 to .126 | 192.168.1.127 |
3 | 192.168.1.128/26 | .129 to .190 | 192.168.1.191 |
4 | 192.168.1.192/26 | .193 to .254 | 192.168.1.255 |
Four subnets, 62 hosts each, no overlaps, every address accounted for. If the question had instead said "each subnet must support at least 50 hosts", you would solve 2^h − 2 ≥ 50, get h = 6, and land on the same /26 from the other direction.
[DIAGRAM: the /24 block as a single bar of 256 addresses, divided into four equal segments of 64, each labelled with its network address, host range, and broadcast, showing the block-size-of-64 spacing.]
Subnetting questions in GATE, UGC NET and placements
GATE CS asks the numerical directly. Given an address and mask, find the network address, the number of hosts, the broadcast, or the number of subnets. Supernetting and variable-length subnet masks (VLSM), where subnets of different sizes share one block, are common harder variants. Our GATE CS exam category sequences addressing with routing and the rest of the network layer.
UGC NET Computer Science favours the conceptual and quick numeric: identify the class, read a CIDR prefix, or compute hosts per subnet in one step. Know the class boundaries cold.
Placement and company tests ask the practical version, "what is a subnet mask", "how many hosts does a /26 give", and occasionally a small VLSM design. The block-size method is what lets you answer these in seconds at a whiteboard, so practising for placements pays off on the placement preparation category too.
KnowledgeGate's published question bank carries over two thousand Computer Networks questions, and IP addressing is one of its densest sub-areas, so there is plenty of drill on exactly these patterns.
Practise it, do not just read it
Subnetting is a skill, not a fact, and it only gets fast with repetition.
Work the full topic with solved numerics on the Network Layer IP Addressing learn module.
For GATE-depth Computer Networks across the whole syllabus, GATE Guidance by Sanchit Sir sequences addressing with the transport and application layers.
The natural next topic is the transport layer, TCP vs UDP, which rides on top of the IP layer you just subnetted.
Learn the two formulas, use the block-size shortcut, and hand-solve one full subnetting table like the one above. Do that a dozen times, and subnetting turns from a feared numerical into free marks.
Ready to test yourself? Work through our solved subnetting and IP addressing MCQs, each answered in a couple of lines, to see exactly how these ideas are examined.