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 -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 -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 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| class | leading bits | first octet | network / host bits | networks | hosts per network | default 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).
- Class A: leading bit ; first octet to (usable); network bits, host bits.
- Class B: leading bits ; first octet to ; .
- Class C: leading bits ; first octet to ; .
- Class D: leading bits ; first octet to : multicast (group addresses, no network/host split).
- Class E: leading bits ; first octet to : reserved.
The number of networks is ; for class A it is minus the two reserved first octets and , so . The number of hosts per network is : the host part all zeros names the network itself, the host part all ones is the broadcast address. A class A network has hosts, class B , class C .
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):
| address | meaning |
|---|---|
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.255 | limited 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/16 | private addresses, not routed on the public Internet (used with NAT, NAT) |
169.254.0.0/16 | link-local, self-assigned when no DHCP answers |
| class D | multicast 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 lies in , class C, network part 200.100.50, network address 200.100.50.0, broadcast address 200.100.50.255, 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 computers did not fit in a class C ( hosts) and took a class B ( hosts), wasting about 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
Easy10.2.3.4: first octet , class A, network 10.0.0.0, 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
EasyClass A: networks of hosts. Class B: networks of hosts. Class C: networks of hosts. Classes A, B and C together use of the address space.
EX 3Broadcast and network address
Medium192.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?" . (b) "Which class does 191.255.1.1 belong to?" B (the first octet is the last of ). (c) "An address with all host bits 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
- bits, dotted decimal. Class A starts (first octet to ), B ( to ), C ( to ), D (multicast), E .
- Networks: , , . Hosts: , , .
- Host part all : network; all : directed broadcast.
255.255.255.255limited broadcast;127.x.y.zloopback. - Private:
10/8,172.16/12,192.168/16. - An address belongs to an interface.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
No cross-subject links yet.
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
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)
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
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
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 ______.
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?
In the IPv4 addressing format, the number of networks allowed under Class C addresses is
- (a)214
- (b)27
- (c)221
- (d)224
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
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
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
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
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 answerHide
First octet : class C; mask 255.255.255.0; network 192.0.2.0.
Question 2
How many addresses are in class C in total?
Show answerHide
networks times addresses , 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 answerHide
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 ; hosts .
- 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
My notes (saved in this browser)