CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 3 · Network Layer

Lesson 3.1.3 · Item 43 of 90

Subnet masks, subnetting, network/broadcast & usable hosts

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. What are the network address and directed broadcast address of Class C network 195.1.1.0?
    Stuck? Peek at 3.1.2 Classful addressing (A–E) and special IPv4 addresses
    • Classes by 1st octet: A = 0–127 (0, 8 net bits), B = 128–191 (10, 16 net bits), C = 192–223 (110, 24 net bits), D = 224–239 (1110, multicast), E = 240–255 (1111, reserved).
    • Usable hosts = 2ʰ − 2 (exclude host all-0s = network address, host all-1s = directed broadcast).
    • Specials: 0.0.0.0 = this host (src only); 255.255.255.255 = limited broadcast (local LAN only); 127.x.y.z = loopback.

    Read lesson 3.1.2

  2. What is the result of bitwise AND between 11001010 and 11110000?
    Stuck? Peek at 0.2.3 XOR, 1's complement addition and modulo-2 division
    • AND (mask), OR, NOT (flip), XOR (1 where bits differ).
    • a ⊕ a = 0, a ⊕ 0 = a, (a ⊕ k) ⊕ k = a.
    • 1's complement = flip all bits; 1's-complement addition wraps the end carry back in.
    • Modulo-2: + = − = XOR, no carries; bits ↔ polynomial.
    • Mod-2 division: leading 1 → XOR divisor; leading 0 → XOR zeros; remainder = (divisor length − 1) bits.

    Read lesson 0.2.3

  3. Does a router separate broadcast domains?
    Stuck? Peek at 2.4.2 Ethernet efficiency; switched vs shared Ethernet
    • Shared Ethernet efficiency η = 1/(1 + 5a) (course default); variants 1/(1 + 5.44a), 1/(1 + 6.44a).
    • Switched full-duplex: no collisions, no CSMA/CD, full rate per link.
    • Collision domains: hub = 1; switch/router = 1 per interface.
    • Broadcast domains: only routers split them.

    Read lesson 2.4.2

The Hook

Suppose a university gets one Class B block (150.100.0.0, 65,534 hosts), but has 30 departments in different buildings. Putting all 65,534 computers into one giant broadcast domain would drown the campus in broadcast traffic!

Subnetting solves this: the campus borrows a few bits from the host part to create a subnet-id. To the outside world it is still one network 150.100.0.0, but inside the campus, a 32-bit subnet mask tells local routers how many bits belong to the network + subnet.

Predict First

If you borrow 2 bits from an 8-bit Class C host field to identify subnets, how many subnets do you get, and how many host bits are left in each subnet?

,

With 2 borrowed bits you get 2² = 4 subnets (00, 01, 10, 11), and each subnet has 8 − 2 = 6 host bits, giving 2⁶ − 2 = 62 usable hosts per subnet.

Core Concept

Three-level hierarchy & Borrowed Bits

Subnetting splits the original host part into two pieces: s borrowed subnet bits followed by h remaining host bits.

  • Number of subnets = 2ˢ (where s is the number of bits borrowed from the host field).
  • Addresses per subnet = 2ʰ, and usable hosts per subnet = 2ʰ − 2 (each subnet loses its own all-0s subnet address and all-1s subnet broadcast address!).
GATE convention on number of subnets: Modern routers and GATE use 2ˢ subnets (allowing the all-0s and all-1s subnet-ids). Very old RFC 950 hardware disallowed those two and wrote 2ˢ − 2; always use 2ˢ unless a question explicitly says "all-0s and all-1s subnets are not used".
NNNNNNNNNNNNNNNNSSSSSHHHHHHHHHHHNet-ID (16 bits)Borrowed Subnet-ID s=5Remaining Host-ID h=11
A Class B address (16 net bits) with s = 5 borrowed bits → 2⁵ = 32 subnets, each with h = 11 host bits (2¹¹ − 2 = 2046 hosts).

The Subnet Mask & Bitwise AND

How does a router know how many bits are network+subnet vs host? Every subnet has a 32-bit subnet mask consisting of contiguous 1s (for network + subnet bits) followed by contiguous 0s (for host bits).

Finding the subnet network address:
Subnet Network Address = (IPv4 Address) BITWISE-AND (Subnet Mask)
Finding the subnet broadcast address: Set all host bits (where mask has 0s) to 1.
ItemDotted DecimalLast Octet in BinaryRole
Host IP200.10.20.15010010110 (150)Host inside the 3rd subnet
Subnet Mask255.255.255.19211000000 (192)26 ones (s=2 borrowed), 6 zeros (h=6)
IP AND Mask200.10.20.12810000000 (128)Subnet Network Address (host bits → 0)
Host bits → 1200.10.20.19110111111 (191)Subnet Broadcast Address (128 + 63 = 191)
Bitwise AND with 255.255.255.192 extracts the subnet address 200.10.20.128 in one step.

The Magic-Number (Block-Stride) Method

You don't even need binary on exam day! In the octet where the mask is neither 255 nor 0 (the "interesting octet"), subtract the mask value from 256:

Block stride Δ = 256 − (interesting mask octet).
Subnets in that octet start at multiples of Δ: 0, Δ, 2Δ, 3Δ, …. The broadcast address of each subnet is (next multiple of Δ) − 1.
Subnet 0: .0–.630–63
Subnet 1: .64–.12764–127
Subnet 2: .128–.191128–191
Subnet 3: .192–.255192–255
0255
Mask 255.255.255.192 → stride Δ = 256 − 192 = 64. The 4 subnets start at .0, .64, .128, .192!

Putting it together

  • Subnetting borrows s host bits to create 2ˢ subnets, each with 2ʰ − 2 usable hosts.
  • A subnet mask has contiguous leading 1s and trailing 0s; IP BITWISE-AND Mask gives the subnet network address.
  • The magic stride Δ = 256 − (mask octet) lets you write down every subnet start and broadcast address by simple multiples of Δ.

Visual

# of 1s in octetBinaryMask OctetStride Δ = 256 − MaskHost bits left in octet
1100000001281287
211000000192646
311100000224325
411110000240164
51111100024883
61111110025242
71111111025421
81111111125510
The Subnet Mask Cheat Table — every valid mask octet is 256 − 2ᵏ.

Worked Examples

Easy

A Class C network 192.168.5.0 uses subnet mask 255.255.255.192. Find (a) borrowed bits s, (b) number of subnets, (c) usable hosts per subnet.

Show the full solution

192 = 11000000₂ → (a) s = 2 borrowed bits, leaving h = 6 host bits.
(b) Subnets = 2² = 4.
(c) Usable hosts per subnet = 2⁶ − 2 = 64 − 2 = 62.

Medium

For host IP 200.10.20.150 with subnet mask 255.255.255.192, find its subnet network address, directed broadcast address, first usable host, and last usable host.

Show the full solution

Stride Δ = 256 − 192 = 64. Multiples of 64 are 0, 64, 128, 192. Since 128 ≤ 150 < 192:
Subnet network address = 200.10.20.128.
Subnet broadcast address = 192 − 1 → 200.10.20.191.
First usable host = 200.10.20.129; Last usable host = 200.10.20.190.

GATE

A Class B network 172.16.0.0 is subnetted with mask 255.255.248.0. How many subnets are created, how many usable hosts exist per subnet, and do 172.16.21.5 and 172.16.25.5 belong to the same subnet?

Show the full solution

In the 3rd octet, 248 = 256 − 8 = 11111000₂ → s = 5 borrowed bits. Total host bits left = 3 (in 3rd octet) + 8 (in 4th octet) = 11 bits.
Subnets = 2⁵ = 32. Usable hosts per subnet = 2¹¹ − 2 = 2048 − 2 = 2046.
Stride in 3rd octet Δ = 256 − 248 = 8. Multiples of 8 are 0, 8, 16, 24, 32:
• 172.16.21.5 lies in block 16..23 (subnet 172.16.16.0).
• 172.16.25.5 lies in block 24..31 (subnet 172.16.24.0).
They are in different subnets!

GATE Traps

  • Non-contiguous 1s: A subnet mask like 255.255.255.160 (10100000₂) is INVALID under standard subnetting because the 1s are not contiguous.
  • Class B two-octet host trap: With mask 255.255.248.0, the broadcast address of subnet 172.16.16.0 is 172.16.23.255 (NOT 172.16.16.255!), because all 11 host bits across both octets 3 and 4 become 1!
  • Same-subnet test: Host A sends directly to Host B only if (IP_A & Mask_A) === (IP_B & Mask_A); otherwise A sends the frame to its default router.

Memory Hook

Stride Δ = 256 − Mask. Floor to a multiple of Δ for the network; stop 1 short of the next multiple for broadcast!

Connect the Dots

Subnetting let us divide a big classful block into smaller pieces using a mask of contiguous 1s. Next question (3.1.4): Why keep Classes A, B, and C at all? What if we throw away classes completely and just write the number of 1s in the mask after a slash, like /26?

Self-Test

  1. NAT

    A Class C network is subnetted using mask 255.255.255.224. How many usable hosts per subnet are available?

    Write your answer before opening the key.

  2. MCQ

    What is the directed broadcast address of the subnet containing host 192.168.10.75 with subnet mask 255.255.255.240?

    1. 192.168.10.79
    2. 192.168.10.95
    3. 192.168.10.64
    4. 192.168.10.255
  3. NAT

    An organisation has a Class B network and needs at least 50 subnets. What is the maximum number of usable hosts per subnet it can achieve?

    Write your answer before opening the key.

  4. MSQ

    With subnet mask 255.255.255.192, which of the following IPv4 addresses CANNOT be assigned to a host interface?

    1. 192.168.1.63
    2. 192.168.1.64
    3. 192.168.1.65
    4. 192.168.1.128
  5. MCQ

    Which of the following is NOT a valid contiguous subnet mask?

    1. 255.255.255.248
    2. 255.255.252.0
    3. 255.255.255.200
    4. 255.254.0.0

Rule Card

  • Borrow s bits from host field, leaving h bits → 2ˢ subnets, each with 2ʰ − 2 usable hosts.
  • Subnet address = IP AND Mask; Broadcast = host bits all 1s.
  • Stride Δ = 256 − Mask octet: blocks start at 0, Δ, 2Δ, … and end at Δ−1, 2Δ−1, ….
  • Valid mask octets: 128, 192, 224, 240, 248, 252, 254, 255.

Concept Ledger

  • subnet mask
  • mask AND address
  • subnetting
  • subnet id
  • borrowed bits
  • number of subnets 2ˢ
  • usable hosts 2ʰ − 2
  • subnet network/broadcast address

Answer Vault

Try the questions first. Open when you are ready to check.

Warm-up answers

  1. Network: 195.1.1.0; Directed broadcast: 195.1.1.255.
  2. 11000000 (AND with 1 keeps the bit; AND with 0 clears the bit to 0).
  3. Yes — each interface of a router connects to a separate broadcast domain (a separate LAN/subnet).

Self-test answers

  1. 30 — 224 = 11100000₂ → 3 ones, 5 zeros (h = 5). Usable hosts = 2⁵ − 2 = 32 − 2 = 30.
  2. A — Stride Δ = 256 − 240 = 16. Multiples of 16: 0, 16, 32, 48, 64, 80. 75 is in 64..79 → subnet = .64, broadcast = 192.168.10.79.
    • B: 95 is the broadcast of the next block (80..95).
    • C: 64 is the subnet network address, not the broadcast address.
    • D: .255 is the unsubnetted Class C broadcast.
  3. 1022 — To get ≥ 50 subnets, borrow s bits with 2ˢ ≥ 50 → minimum s = 6 bits (2⁶ = 64 subnets). Remaining host bits h = 16 − 6 = 10 → usable hosts = 2¹⁰ − 2 = 1022.
  4. ABD — Stride Δ = 64. Subnets start at .0, .64, .128, .192 (network addresses) and end at .63, .127, .191, .255 (broadcast addresses). Only .65 is a usable host.
    • C: .65 is the first usable host of the .64 subnet.
  5. C — 200 = 128 + 64 + 8 = 11001000₂, which has non-contiguous 1s. Valid mask octets must come from {0, 128, 192, 224, 240, 248, 252, 254, 255}.
    • A: 248 = 11111000₂ is valid.
    • B: 252 = 11111100₂ is valid.
    • D: 254 = 11111110₂ is valid.

Flashcards

  1. How do you compute the subnet network address from an IP and subnet mask?
    Reveal answerBitwise AND: Subnet = IP & Mask.
  2. If s bits are borrowed leaving h host bits, how many subnets and usable hosts per subnet?
    Reveal answer2ˢ subnets and 2ʰ − 2 usable hosts per subnet.
  3. What is the stride Δ for mask octet 240, and where do the first three subnets start?
    Reveal answerΔ = 256 − 240 = 16; subnets start at 0, 16, 32 (broadcasts at 15, 31, 47).
  4. List the 8 non-zero valid subnet mask octet values.
    Reveal answer128, 192, 224, 240, 248, 252, 254, 255.

Exam shortcuts

  • Stride shortcut Δ = 256 − M: Subnet start = ⌊octet / Δ⌋ × Δ, Broadcast = subnet start + Δ − 1. — finding subnet and broadcast addresses in < 10 seconds without binary conversion.
  • Address loss cost of subnetting: Splitting a network into K subnets loses 2K addresses total (compared to 2 lost before subnetting). — questions asking "How many usable host addresses are lost when subnetting?" → 2(2ˢ − 1) additional addresses lost.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.