E ExamMaster

Computer Networks · Computer Networks

IP Addressing, CIDR and NAT

IPv4 addressing, subnetting with CIDR, fragmentation, and support protocols like ARP, DHCP and NAT.

The tea page still needs numbers. Meera's phone is 192.168.1.42/24 on home Wi-Fi. The shop is 203.0.113.10 on 203.0.113.0/28. This lesson is what those dotted numbers and /n prefixes mean, how many hosts a block holds, and how a private phone reaches a public shop through NAT.

  • Computer Networks
  • Hard level
  • 7 concepts
  • 5 practice questions

1IPv4 and dotted decimal

Meera's phone has an IPv4 address: 192.168.1.42. An IPv4 address is 32 bits — thirty-two ones and zeros that name one interface on the Internet. Humans write those 32 bits as four decimal octets separated by dots. An octet is 8 bits, so each group is a number from 0 through 255. 192, 168, 1, and 42 are four such groups. The dots are only for reading; the address is still one 32-bit number.

Every later subnetting question asks how those 32 bits split: some bits name the network (the group of machines that share a prefix), and the rest name the host (this phone inside that group). 192.168.1.256 is not an address — 256 does not fit in 8 bits.

Figure. Four equal octets make one 32-bit address. Subnet masks decide how many leading bits belong to the network.

How to read an address

  1. Four octetsRead left to right: each group is one byte (8 bits).
  2. Range checkEach octet must be 0–255; 256 or more is invalid dotted decimal.
  3. Think in bitsSubnetting works on the full 32-bit pattern, not on the decimal groups alone.
Which of the following is a valid IPv4 address in dotted decimal?
  1. 192.168.1.256
  2. 192.168.1.10
  3. 300.10.20.1

Each octet must be 0–255. 192.168.1.256 and 300.10.20.1 each have an octet above 255; 192.168.1.10 is in range.

2Classful defaults and CIDR

The shop's address is written 203.0.113.10/28. The /28 is CIDR — Classless Inter-Domain Routing. It means the first 28 of the 32 bits are the network prefix, the shared part, and the remaining 4 bits name hosts inside that block. A prefix is just 'the first n bits stay fixed.'

Older classful defaults still appear as shortcuts: Class A meant /8, Class B /16, Class C /24. They are default prefix lengths, not a second addressing system. The /n is what the phone and the shop actually use. The shop's /28 is smaller than a Class C /24 — 4 host bits, not 8.

Figure. Classful /8 /16 /24 sizes are special cases; CIDR lets the prefix length be any integer mask.

From class letter to prefix length

  1. Spot the class habitA starts 0…, B starts 10…, C starts 110… — each implied a default /8, /16, /24.
  2. Read CIDR/n counts network bits from the left; everything after is host space.
  3. Prefer prefixWhen a question gives /26, ignore the old class default and subnet on 26.
Classful defaults (historical)
ClassFirst bitsDefault maskHost bits
A0/824
B10/1616
C110/248
A network is written 172.16.0.0/12. Compared with classful defaults, this mask is
  1. Exactly the Class B default /16
  2. Shorter than Class B — a supernet aggregating many /16 blocks
  3. Invalid because 172.x is always Class C /24

/12 keeps only 12 network bits, so one prefix covers 172.16.0.0 through 172.31.255.255 — far wider than the old Class B /16.

3Subnet mask and host bits

A /n mask has n leading 1-bits and 32-n trailing 0-bits. Those trailing zeros are the host bits: the bits that can change from one machine to the next inside the block. For the shop's /28, host bits h = 32-28 = 4. The block then holds 2^h = 16 addresses. Two of them are reserved: the all-zeros host part is the network address (203.0.113.0), and the all-ones host part is the broadcast address (203.0.113.15). A /28 does not give 16 usable IPs — usable hosts are 14.

A /24 mask is 255.255.255.0. A /26 mask is 255.255.255.192 because the last octet begins 11000000. Subtract the two reserved endpoints unless the question names a /31 point-to-point link. Meera's home /24 has 8 host bits: 256 addresses, 254 usable.

Figure. The /26 line splits 32 bits into a fixed prefix and a 6-bit host field — 64 addresses, 62 assignable. Box widths match the 26:6 bit split.

Mask to counts

  1. Host bitsHost bits h = 32 - n from the CIDR prefix /n.
  2. Total addressesBlock size = 2^h addresses in the subnet.
  3. Usable hostsDefault: usable = 2^h - 2 (network + broadcast reserved).

Usable hosts in /26

The shop's staff VLAN is 192.168.10.0/26 — a different block from Meera's home /24. How many usable host addresses are in 192.168.10.0/26?

  • Host bits h = 32 − 266
  • Total addresses = 2^664
  • Usable = 64 − 2 (network + broadcast)62

Pro tip. Memorise powers of two through 2^{16}. /26 always means 64 total and 62 usable — the same pair GATE repeats.

Coding lab. Usable hosts on the shop /28 runs in the app, with checks on your output.

How many usable host addresses are in a /24 IPv4 subnet?
  1. 256
  2. 254
  3. 252

/24 has 8 host bits → 256 addresses, minus network and broadcast → 254 usable. 256 forgets the two reserved addresses.

4Block size and network address

To find which subnet a host belongs to, locate the interesting octet — the one where the mask is neither 0 nor 255 — and jump in steps of the block size. Block size = 256 minus the mask value in that octet. The network address has host bits all zero in that block; broadcast is all ones. Never guess from the decimal pattern alone — align to the block boundary.

Meera's phone 192.168.1.42/24 is easy: the last octet's mask is 0, so the whole last octet is host, and the network is 192.168.1.0. A neighbour on a /25 at 192.168.1.130 sits in the upper 128-wide block starting at 192.168.1.128. The shop 203.0.113.10/28 has block size 16 in the last octet, so its network is 203.0.113.0.

Figure. A /25 splits the last octet into two 128-wide blocks. Host .130 lands in the upper block starting at .128.

Which subnet is this host in?

  1. Interesting octetFind the octet where the subnet mask is between 0 and 255.
  2. Block sizeBlock = 256 - mask byte (e.g. /25 → mask 128 → block 128).
  3. Align downThe network address is the largest multiple of the block size not exceeding the host octet.

Network address for a host

For host 192.168.1.130/25, what is the subnet (network) address?

  • /25 → mask 255.255.255.128 → block in last octet = 256 − 128128
  • Subnet starts: .0 and .128 (steps of 128).0 block [0–127], .128 block [128–255]
  • 130 lies in .128 block → network address192.168.1.128

Pro tip. Count upward in steps of the block size in the interesting octet: 0, 128, 256… The host falls into the interval it crosses.

Host 10.20.30.200/27 belongs to which network address?
  1. 10.20.30.192
  2. 10.20.30.200
  3. 10.20.30.224

/27 mask 224 → block size 32. Multiples in the last octet: …160, 192, 224. 200 sits in 192–223, so the network is 10.20.30.192.

5Private IPv4 ranges

Meera's 192.168.1.42 is a private address. RFC 1918 names three ranges that routers on the public Internet will not forward: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. Hosts with these addresses reach the wider Internet only through NAT or a proxy. The shop's 203.0.113.10 is a documentation public address in this lesson — it is not in those three ranges.

The three prefixes are the fact to keep, not individual host numbers. 8.8.8.8 is public. 172.16.5.1 is private. 192.168.1.42 is private because it sits inside 192.168.0.0/16.

Figure. To scale on the second octet: the private slice of 172.x is only the 16-value band 172.16 – 172.31 (/12) — the boundary trap. 10.x.x.x is private end to end and 192.168.x.x is private across its whole third octet; only 172 splits mid-range.

Spot a private address

  1. 10/8Any 10.x.x.x is private.
  2. 172.16/12172.16.0.0 through 172.31.255.255 — not all 172.x.
  3. 192.168/16192.168.x.x is private; 192.x otherwise is usually public.
RFC 1918 private ranges
RangeCIDRMnemonic
10.0.0.0 – 10.255.255.255/8Class-A-sized private block
172.16.0.0 – 172.31.255.255/12172.16–31 only
192.168.0.0 – 192.168.255.255/16Home-router default
Which address is in a private RFC 1918 range?
  1. 8.8.8.8
  2. 172.16.50.10
  3. 203.0.113.44

172.16.50.10 sits in 172.16.0.0/12. 8.8.8.8 is public; 203.0.113.44 is TEST-NET-3 documentation space (RFC 5737), not RFC 1918 private.

6ARP, DHCP and DNS

Three helpers get the tea-page packet onto the first hop. DHCP, Dynamic Host Configuration Protocol, is how the phone got 192.168.1.42 and learned that 192.168.1.1 is the gateway — the router that leaves the home network. ARP, Address Resolution Protocol, maps an IP on this LAN to a MAC address, the hardware number on the Wi-Fi card. The phone ARPs for 192.168.1.1 before it can send the first frame.

DNS, Domain Name System, maps the human name shop.rao.example to 203.0.113.10. That lookup is an application job and is taught in full in the DNS lesson. Here the only point is the split: DHCP hands the phone an address, ARP finds the next-hop MAC, DNS finds the shop's IP.

Figure. DHCP leases L3 config, ARP resolves next-hop MAC, DNS maps names — three different questions, three protocols.

Which protocol when?

  1. Need a MACSame subnet delivery → ARP broadcast: who has this IP?
  2. Need an addressHost boots without config → DHCP discover/offer/request/ack.
  3. Need a nameBrowser has a hostname → DNS query returns A/AAAA records.
Support protocols at a glance
ProtocolQuestion it answersTypical layer
ARPIP → MAC on this LANLayer 2/3 boundary
DHCPAssign IP, mask, gateway, DNSApplication (UDP 67/68)
DNSName → IP (and mail MX, etc.)Application (UDP/TCP 53)
A newly powered laptop has no IP address configured. Which protocol supplies one automatically?
  1. ARP
  2. DHCP
  3. DNS

DHCP assigns addresses. ARP maps IP to MAC after an address exists; DNS resolves names, not bare L3 config.

7NAT address translation

The shop cannot send a reply to 192.168.1.42. That address is private — it is not unique on the Internet, and public routers will not deliver to it. NAT, Network Address Translation, on Meera's home router rewrites the packet. Going out, source 192.168.1.42 plus the phone's local TCP port become the router's public address 198.51.100.80 plus a public port. Coming back, the router rewrites the destination to 192.168.1.42.

Many private hosts can share one public IP because the router remembers the address-and-port pair. NAT conserves IPv4 addresses. It does not encrypt, and it is not DHCP.

Figure. Several hosts on a private LAN share one routable public address through the NAT router's translation table.

Outbound through NAT

  1. Private sourceHost 192.168.1.50:5000 sends to a public server.
  2. RewriteNAT router replaces source with public IP:ephemeral port and logs the mapping.
  3. ReturnReply hits the public IP; NAT table restores 192.168.1.50:5000.
Why do RFC 1918 private hosts need NAT to browse the public Internet?
  1. Private addresses are invalid and dropped by every router
  2. Private addresses are not globally routable — NAT maps them to a public IP for outbound traffic
  3. NAT encrypts traffic so private addresses become secure

Private space is intentionally unroutable on the Internet. NAT translates to a routable public address; it does not encrypt.

Notes

  • IPv4 is 32 bits in dotted decimal (four octets); classful addressing gives Class A (/8), B (/16), C (/24) default masks.
  • CIDR notation /n means the first n bits are the network prefix; the remaining 32-n bits identify hosts within the subnet.
  • In each subnet two addresses are reserved: the all-zeros host part is the network address and all-ones is the broadcast address.
  • ARP maps an IP address to a MAC address on a LAN; DHCP dynamically assigns IP addresses; DNS maps names to IPs.
  • NAT lets many private hosts share one public IP by translating address/port pairs, conserving scarce IPv4 addresses.

Formulas

  • Total addresses in a /n subnet = 2^{(32-n)}.
  • Usable hosts per subnet = 2^{(32-n)} - 2 (excluding network and broadcast).
  • Number of subnets when borrowing k bits = 2^k.
  • Subnet mask for /n has n leading 1s (e.g. /24 = 255.255.255.0).
  • Block size in the interesting octet = 256 - (mask value of that octet).

Exam traps & shortcuts

  • For usable hosts, always subtract 2 (network + broadcast) unless it's a /31 point-to-point link.
  • Find the interesting octet from the mask, then jump in steps of the block size to locate subnet boundaries.
  • Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — these are never routed on the public Internet.

Reference tables

Every GATE-style count or boundary question reduces to one of these.

Subnetting formulas
QuantityFormulaTrap to avoid
Total addresses in /n2^{(32-n)}Confusing /n with host bits directly
Usable hosts (default)2^{(32-n)} - 2Forgetting network + broadcast; /31 is the exception
Subnets when borrowing k bits2^kBorrowing from the host portion, not the mask decimal
Block size in interesting octet256 - mask byteUsing 256 instead of subtracting the mask value
Subnet mask /nn leading 1-bits/24 = 255.255.255.0, not 255.255.0.0

Recap

The two numbers on the tea fetch, and how a private phone reaches a public shop.

IPv4
32 bits, four octets 0–255. Dots are for reading. Phone 192.168.1.42; shop 203.0.113.10.
CIDR
/n is the prefix length. Shop /28 → 4 host bits → 16 addresses → 14 usable, not 16.
Block
Align to block size in the interesting octet. /28 block 16 → shop network 203.0.113.0.
Private + NAT
192.168.1.42 is RFC 1918. NAT rewrites it to 198.51.100.80. DHCP assigned the phone; ARP found the gateway MAC.

Practise IP Addressing, CIDR and NAT

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 5 exam-style questions on this topic, with explanations
  • A 6-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.