G27
Self-checkedTier 1 7 min readcn.ipv4-addressing

IPv4 addressing and classful addressing

The 32-bit IPv4 address, dotted decimal notation and conversion to binary, the network part and the host part, the five address classes with their leading bits, first-octet ranges, numbers of networks and hosts (126 / 16 384 / 2 097 152 networks and 16 777 214 / 65 534 / 254 hosts), default masks, the special addresses (this network, limited and directed broadcast, loopback, private ranges, multicast), and why an address belongs to an interface and not to a host; counts are verified by enumeration and the address arithmetic against Python's ipaddress module.

Why it exists

Every interface on the Internet needs a unique number so that packets can be routed to it. IPv4 uses a 3232-bit number. A routing decision cannot look up each of billions of hosts, so the number is split into a network part (common to all machines on one network, used by routers) and a host part (identifies the machine within the network). The original rule for the split was fixed by the first bits of the address: the classes. The classes are obsolete in practice (replaced by CIDR, next page) but their counts and ranges are still asked in GATE.

Prerequisites

You need the network layer's job: end-to-end delivery by address (layering).

Precise definitions

An IPv4 address is a 3232-bit number, written in dotted decimal: four bytes in decimal separated by dots. Example: 172.16.37.5 is 10101100.00010000.00100101.00000101. There are 232=4 294 967 2962^{32} = 4\,294\,967\,296 addresses.

An address identifies an interface, not a host: a router with three network cards has three addresses, one in each network it connects, and a laptop with Ethernet and Wi-Fi has two.

Classful addressing assigned the split from the leading bits of the address:

Classful IPv4 addressing: start

Computed by a script, not typed
classleading bitsfirst octetnetwork / host bitsnetworkshosts per networkdefault mask
class A
class B
class C
class D
class E

Step 0

The classful scheme is obsolete but its counts are asked in exams. First-octet ranges: the class A range 1 … 126 leaves out 0 and 127 (loopback).

0 / 5
computed by script: exact integer and fraction arithmetic, address calculations on bit patterns. python3 scripts/gen-cn2-traces.py
  • Class A: leading bit 00; first octet 11 to 126126 (usable); 88 network bits, 2424 host bits.
  • Class B: leading bits 1010; first octet 128128 to 191191; 16+1616 + 16.
  • Class C: leading bits 110110; first octet 192192 to 223223; 24+824 + 8.
  • Class D: leading bits 11101110; first octet 224224 to 239239: multicast (group addresses, no network/host split).
  • Class E: leading bits 11111111; first octet 240240 to 255255: reserved.

The number of networks is 2network bits−leading bits2^{\text{network bits} - \text{leading bits}}; for class A it is 27=1282^7 = 128 minus the two reserved first octets 00 and 127127, so 126126. The number of hosts per network is 2host bits−22^{\text{host bits}} - 2: the host part all zeros names the network itself, the host part all ones is the broadcast address. A class A network has 16 777 21416\,777\,214 hosts, class B 65 53465\,534, class C 254254.

A subnet mask has ones in the network (and subnet) positions and zeros in the host positions; a bitwise AND of an address and the mask gives the network address. Default masks: class A 255.0.0.0, class B 255.255.0.0, class C 255.255.255.0.

Special addresses (quoted from the RFCs; the exam usually needs only the first four):

addressmeaning
host part all zeros (for example 192.168.5.0 in class C)the network itself, never a host
host part all ones (192.168.5.255)directed broadcast to every host of that network
255.255.255.255limited broadcast: every host on the local network, not forwarded by routers
0.0.0.0"this host" (used by a host that does not yet know its address, for example when starting DHCP) or the default route
127.0.0.0/8 (first octet 127, for example 127.0.0.1)loopback: the packet goes to the sending host itself
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16private addresses, not routed on the public Internet (used with NAT, NAT)
169.254.0.0/16link-local, self-assigned when no DHCP answers
class Dmulticast groups

How it works

Reading an address

To find the class, look at the first octet in binary (or the decimal ranges above). To find the network address, keep the network bits and set the host bits to zero. Example: 200.100.50.12: first octet 200200 lies in 192…223192 \dots 223, class C, network part 200.100.50, network address 200.100.50.0, broadcast address 200.100.50.255, 254254 hosts.

A host decides whether a destination is on its own network by comparing network parts: if the destination's network part equals its own, the packet is sent directly (the destination MAC address is found with ARP); otherwise it is sent to the default router. A router uses the network part to look up the route (routing).

Why classes were replaced

A company with 20002000 computers did not fit in a class C (254254 hosts) and took a class B (65 53465\,534 hosts), wasting about 63 00063\,000 addresses. Class B addresses ran out, class C tables grew huge. Subnetting let an organisation split its network internally; CIDR removed the classes altogether (CIDR and subnetting).

Worked examples

EX 1Class and ranges

Easy

10.2.3.4: first octet 10<12810 < 128, class A, network 10.0.0.0, 16 777 21416\,777\,214 hosts. 150.1.2.3: class B, network 150.1.0.0. 223.255.255.255: class C (the last class C address). 224.0.0.5: class D multicast. 127.0.0.1: loopback, not a usable class A host.

EX 2Counting

Easy

Class A: 27−2=1262^7 - 2 = 126 networks of 224−2=16 777 2142^{24} - 2 = 16\,777\,214 hosts. Class B: 214=16 3842^{14} = 16\,384 networks of 65 53465\,534 hosts. Class C: 221=2 097 1522^{21} = 2\,097\,152 networks of 254254 hosts. Classes A, B and C together use 1/2+1/4+1/8=7/81/2 + 1/4 + 1/8 = 7/8 of the address space.

EX 3Broadcast and network address

Medium

192.168.5.77 is class C: network 192.168.5.0, directed broadcast 192.168.5.255. For 130.45.200.9 (class B): network 130.45.0.0, broadcast 130.45.255.255.

EX 4Typical questions

GATE level

(a) "How many hosts can a class B network have?" 216−2=65 5342^{16} - 2 = 65\,534. (b) "Which class does 191.255.1.1 belong to?" B (the first octet 191191 is the last of 128…191128 \dots 191). (c) "An address with all host bits 11 is used for?" Directed broadcast. (d) "A router has how many IP addresses?" One per interface. (e) "First address of the private class C range?" 192.168.0.0.

Cheat box

Cheat box

  • 3232 bits, dotted decimal. Class A starts 00 (first octet 11 to 126126), B 1010 (128128 to 191191), C 110110 (192192 to 223223), D 11101110 (multicast), E 11111111.
  • Networks: 126126, 16 38416\,384, 2 097 1522\,097\,152. Hosts: 224−22^{24} - 2, 216−22^{16} - 2, 28−2=2542^8 - 2 = 254.
  • Host part all 00: network; all 11: directed broadcast. 255.255.255.255 limited broadcast; 127.x.y.z loopback.
  • Private: 10/8, 172.16/12, 192.168/16.
  • An address belongs to an interface.

Traps and GATE patterns

Connections

CIDR keeps the idea of a network part and a host part but lets the split fall at any bit (CIDR and subnetting). Private addresses make NAT necessary (NAT). Hosts find the MAC address of a neighbour with ARP (ARP, ICMP and DHCP), and the IP header is described on IPv4 fragmentation.

PYQs

11 previous year questions from your book. I re-solved each one myself (11 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · NATQ1 · page 547 of the book
If an IP network uses a subnet mask of
255.255.240.0, the maximum number of IP
addresses that can be assigned to network interfaces
is ______. (answer in integer)
GATE 2022 · MCQ · 1 markQ29 · page 551 of the book
Consider an enterprise network with two Ethernet
segments, a web server and a firewall, connected via

COMPUTER NETWORK
three routers as shown below:

What is the number of subnets inside the enterprise
network?
  • (a)3
  • (b)12
  • (c)6
  • (d)8
GATE 2019 · MCQ · 2 marksQ41 · page 554 of the book
Consider three machines M, N, and P with IP
addresses 100.10.5.2, 100.10.5.5, and 100.10.5.6
respectively.
The
subnet
mask
is
set
to
255.255.255.252 for all the three machines. Which
one of the following is true?
  • (a)M, N and P all belong to the same subnet
  • (b)Only N and P belong to the same subnet
  • (c)M, N, and P belong to three different subnets
  • (d)Only M and N belong to the same subnet
GATE 2015 · NATQ53 · page 556 of the book
In the network 200.10.11.144/27, the fourth octet
(in decimal) of the last IP address of the network
which can be assigned to a host is ______.
GATE 2014 · MCQQ67 · page 558 of the book
Every host in an IPv4 network has a 1-second
resolution real-time clock with battery backup. Each
host needs to generate up to 1000 unique identifiers
per second. Assume that each host has a globally
unique IPv4 address. Design a 50-bit globally unique
ID for this purpose. After what period (in seconds)
will the identifiers generated by a host wrap around?
GATE 2012 · MCQQ74 · page 559 of the book
In the IPv4 addressing format, the number of
networks allowed under Class C addresses is
  • (a)214
  • (b)27
  • (c)221
  • (d)224
GATE 2010 · MCQ · 2 marksQ79 · page 561 of the book
Suppose computers A and B have IP addresses
10.105.1.113 and 10.105.1.91 respectively. They
both use the same netmask N. Which of the values
of N given below should not be used if A and B
should belong to the same network?
  • (a)255.255.255.0
  • (b)255.255.255.128
  • (c)255.255.255.192
  • (d)255.255.255.224
GATE 2008 · MCQ · 2 marksQ83 · page 561 of the book
If a class B network on the Internet has a subnet mask
of 255.255.248.0, what is the maximum number of
hosts per subnet?
  • (a)1022
  • (b)1023
  • (c)2046
  • (d)2047
GATE 2007 · MCQ · 2 marksQ87 · page 562 of the book
The address of a class B host is to be split into
subnets with a 6-bit subnet number. What is the
maximum number of subnets and the maximum
number of hosts in each subnet?
  • (a)62 subnets and 262142 hosts
  • (b)64 subnets and 262142 hosts
  • (c)62 subnets and 1022 hosts
  • (d)64 subnets and 1024 hosts
GATE 2006 · MCQ · 2 marksQ89 · page 562 of the book
Two computers C1 and C2 are configured as follows:
C1 → IP: 203.197.2.53, Mask: 255.255.128.0
C2 → IP: 203.197.75.201, Mask: 255.255.192.0

Which statement is true?
  • (a)C1 and C2 both assume they are on the same network
  • (b)C2 assumes C1 is on same network, but C1 assumes C2 is on a different network
  • (c)C1 assumes C2 is on same network, but C2 assumes C1 is on a different network
  • (d)C1 and C2 both assume they are on different networks
GATE 2005 · MCQ · 1 markQ91 · page 562 of the book
An organization has a class B network and wishes to
form subnets for 64 departments. The subnet mask
would be:
  • (a)255.255.0.0
  • (b)255.255.64.0
  • (c)255.255.128.0
  • (d)255.255.252.0 COMPUTER NETWORK

Self-check

Question 1

Class and default mask of 192.0.2.1?

Show answer

First octet 192192: class C; mask 255.255.255.0; network 192.0.2.0.

Question 2

How many addresses are in class C in total?

Show answer

2212^{21} networks times 282^8 addresses =229=536 870 912= 2^{29} = 536\,870\,912, one eighth of the address space.

Question 3

What is the broadcast address of the network 172.20.0.0 (class B, default mask)?

Show answer

172.20.255.255.

Revision card

One-screen revision

  • A: 0xxx, 8+24; B: 10xx, 16+16; C: 110x, 24+8; D: multicast; E: reserved.
  • Networks 126/16 384/2 097 152126 / 16\,384 / 2\,097\,152; hosts 2h−22^h - 2.
  • Zeros: network; ones: broadcast; 127: loopback; private ranges for NAT.

References

  • ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 4, Section 4.3.3 (IPv4 addressing)
  • ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.6.2 (IP addresses)
  • ·Forouzan, Data Communications and Networking (5th edition), Chapter 19 (Network layer: logical addressing)

Verification

scripts/enum-checks/cn_net_check.py: dotted-decimal conversion, network and broadcast addresses, masks and host counts agree with Python's ipaddress module on 5000 random addresses and prefix lengths; the class of every first octet 0 to 255 was tested; the numbers of networks and hosts per class were obtained by counting the first-octet ranges (126 class A networks, 16384 class B, 2097152 class C); the private ranges were tested for membership on 5000 random addresses against ipaddress networks. QUOTED from the RFCs / textbooks and not checked here: the special-address list (0.0.0.0, 255.255.255.255, 127.0.0.0/8, link-local 169.254.0.0/16), the private ranges of RFC 1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), the multicast and reserved class definitions, and the convention that class A has 126 usable networks (0 and 127 are reserved; some books count 128 networks or 127 networks). Hosts per network are 2^h - 2 in the usual exam convention. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never