IP Addressing in Computer Networks: Classes, Subnetting, CIDR, and Worked Examples for GATE

Build IP addressing from its 32-bit foundation through classful ranges, subnetting, VLSM, CIDR aggregation, and longest prefix match with checked examples.

KnowledgeGate Team

Exam prep & CS education

Updated 29 Aug 20266 min read

Every network-layer question in GATE ultimately stands on IP addressing. Can you split a block, name its broadcast address, and pick the right routing-table entry in under a minute? Many candidates remember class ranges but freeze on “which subnet contains this host” because they have not practised binary block arithmetic. IP addressing problems commonly use three numerical patterns.

Anatomy of an IPv4 address

An IPv4 address has 32 bits, written as four dotted-decimal octets from 0 to 255. For example, 192.168.10.150 is:

11000000.10101000.00001010.10010110

The address has a network part and a host part. A subnet mask, or its equivalent /n prefix, marks the split. A /24 prefix means that the first 24 bits identify the network, so its mask is 255.255.255.0.

Three derived addresses appear repeatedly in questions:

  • The network address has every host bit set to 0.

  • The directed broadcast address has every host bit set to 1.

  • The usable host range lies between those two addresses.

A /n block contains 2^(32-n) total addresses and normally 2^(32-n) - 2 usable host addresses. The two subtracted addresses are the network and directed broadcast addresses.

Know the special cases cold: 127.0.0.0/8 is loopback, 255.255.255.255 is the limited broadcast address, and 0.0.0.0 can represent this host or an unspecified address. The private ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. Private hosts normally use NAT when communicating with the public Internet.

Classful addressing and its limitation

Classful addressing divided IPv4 space by the first octet:

Class

First octet

Starting bits

Default prefix

Use

A

1 to 126

0

/8

Unicast networks

B

128 to 191

10

/16

Unicast networks

C

192 to 223

110

/24

Unicast networks

D

224 to 239

1110

Not applicable

Multicast

E

240 to 255

1111

Not applicable

Reserved

A class B network provides 2^16 - 2 = 65,534 usable hosts. An organisation needing 2,000 hosts would therefore leave roughly 63,500 addresses unused. Eight class C networks could provide enough addresses, but managing several separate networks is awkward. Subnetting improved allocation within networks, and CIDR later removed fixed class boundaries.

Class identification can still be tested as a fact. For example, 145.10.20.3 is class B because 145 lies between 128 and 191. For numerical work, use this rule: if a prefix or mask is given, treat the problem as classless and ignore the old class default.

Subnetting with a four-way split

Subnetting borrows host bits to create smaller networks. Extending a prefix by k bits creates 2^k equal subnets. In the mask octet where the split occurs, calculate block size = 256 - mask octet; subnet boundaries are multiples of that block size.

Split 192.168.10.0/24 into four equal subnets. Four subnets need two borrowed bits because 2^2 = 4. The new prefix is /26, the mask is 255.255.255.192, and the block size is 256 - 192 = 64. Six host bits remain, so each subnet has 2^6 = 64 addresses and 64 - 2 = 62 usable hosts.

Subnet

Usable hosts

Broadcast

192.168.10.0/26

.1 to .62

.63

192.168.10.64/26

.65 to .126

.127

192.168.10.128/26

.129 to .190

.191

192.168.10.192/26

.193 to .254

.255

Which subnet contains 192.168.10.150? The boundaries are 0, 64, 128, and 192. Since 150 lies in the 128 to 191 block, the network is 192.168.10.128/26 and the broadcast is 192.168.10.191. For a slower build of the same method, study IP Addressing and Subnetting Explained.

A /24 block split into four /26 subnets of 62 usable hosts each, with host 192.168.10.150 landing inside the .128/26 block.

VLSM for unequal requirements

Fixed-length subnetting wastes addresses when departments differ in size. Variable Length Subnet Masking assigns each department the smallest block that fits, with the largest requirement allocated first.

Suppose 192.168.10.0/24 must serve departments needing 100, 50, 25, and 5 hosts:

Need

Smallest fit

Allocation

Usable range

100

/25, 126 usable

192.168.10.0/25

.1 to .126

50

/26, 62 usable

192.168.10.128/26

.129 to .190

25

/27, 30 usable

192.168.10.192/27

.193 to .222

5

/29, 6 usable

192.168.10.224/29

.225 to .230

The addresses from .232 through .255 remain free. This demonstrates both VLSM rules: round each host need up to a power-of-two block after allowing for network and broadcast, then allocate in descending size so every block begins on a valid boundary.

CIDR aggregation and longest prefix match

CIDR allows any /n prefix and can aggregate adjacent networks into one route. Consider 200.24.0.0/24, 200.24.1.0/24, 200.24.2.0/24, and 200.24.3.0/24. Their third octets run from 0 to 3, sharing the first six bits as 000000xx. The four routes therefore aggregate to 200.24.0.0/22, which contains 2^(32-22) = 1,024 addresses. Aggregation works only when equal-sized blocks are contiguous and the first block is aligned to the combined block size.

Routers then apply longest prefix match. Suppose a forwarding table contains:

Prefix

Next hop

Covered range

144.16.0.0/16

R1

144.16.0.0 to 144.16.255.255

144.16.64.0/20

R2

144.16.64.0 to 144.16.79.255

144.16.68.0/22

R3

144.16.68.0 to 144.16.71.255

0.0.0.0/0

R4

Default route

144.16.68.117 matches /16, /20, and /22. The /22 has the longest matching prefix, so the packet goes to R3. 144.16.80.5 matches only /16, so it goes to R1. 200.1.1.1 matches no specific entry and therefore uses default route R4.

Nested address ranges for the routing table, where 144.16.68.117 matches the innermost /22 route to R3 as the longest prefix.

Once a router selects an entry, the question of how that route was learned belongs to Routing Algorithms: Distance Vector vs Link State.

Traps that cost easy marks

Forgetting the minus two. A /26 has 64 addresses but normally only 62 usable hosts. A /28 has 16 addresses and 14 usable hosts, so it cannot serve 15 hosts. Write the total and usable formulas before calculating. Treat /31 point-to-point links and /32 host routes as special cases only when the question invokes them.

Choosing the wrong boundary. For a /26, list 0, 64, 128, and 192 before placing the target. Network .128 and broadcast .191 are not assignable hosts in the third block.

Falling back to class defaults. A destination under 144.16.68.0/22 must be evaluated using /22, not class B's historical /16. Also keep a mask separate from its wildcard complement: 255.255.255.192 is the mask, while 0.0.0.63 is its complement.

How GATE and interviews frame IP addressing

IP addressing sits within Computer Networks in the GATE CS syllabus. Verify the current concept list and paper pattern on the official GATE exam papers and syllabus page. Any specific marks split, question count, or date should come from the information brochure published by that year's organising institute.

Typical questions ask you to identify a class or special address, calculate a network, host range, or broadcast address, and apply longest prefix match to a forwarding table. Interviews often begin with “how many usable hosts does a /26 have?” and follow with overlapping routes, private ranges, NAT, or the reason CIDR reduces routing-table size. A strong answer shows the bit or block arithmetic.

After learning the method, solve Subnetting MCQs: 12 Solved IP Addressing Questions, then attempt topic-wise networking tests under time.

The short version and next step

IPv4 uses 32 bits and a mask. Keep class ranges as identification facts, but use the supplied prefix for all arithmetic. A /24 split four ways becomes four /26 networks with 62 usable hosts each, and .150 lies in the .128/26 block. VLSM allocates largest first, four aligned /24 routes can combine into 200.24.0.0/22, and longest prefix match sends 144.16.68.117 to R3.

Pressure-test the topic against the clock with the GATE Test Series with mocks and topic-wise tests, or browse more GATE CS subject notes.