Network Layer · Computer Networks

Logical Addressing — IPv4

Watch lectures
SVGVector Architecture Diagram (SVG)
COMPUTER NETWORKS · Module 3★ High PriorityLogical Addressing: IPv4IT Sem 6 · Code 100602 · Classes, CIDR and SubnettingMNEMONICClass by leading bits: A 0, B 10, C 110, D 1110, E 1111.Usable hosts = 2^h - 2; network = IP AND mask; broadcast = host bits all 1.Core Breakdown32-bitIPv4 address is 32 bits: 2^32 = 4,294,967,296 addresses.Dotted decimal: four octets 0-255, e.g. 192.168.1.1.ClassfulClasses A to E from leading bits; A /8, B /16, C /24 default masks.Rigid blocks: 300 hosts forced a Class B, about 99.5% wasted.SpecialHost bits 0 = network ID, host bits 1 = directed broadcast.255.255.255.255 limited broadcast; 127.0.0.1 loopback; 169.254/16 APIPA.PrivateRFC 1918: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.Not routable on the Internet; used inside LANs behind NAT.CIDRClassless since 1993: any prefix length /n, mask has n ones.Subnets = 2^s, addresses = 2^h, usable hosts = 2^h - 2.Example200.10.20.75 /27: 75 AND 224 = 64, so network 200.10.20.64.Broadcast .95, hosts .65 to .94, usable hosts 2^5 - 2 = 30.Diagram: Address ClassesA0Net 7bHost 24 bitsB10Net 14 bitsHost 16 bitsC110Net 21 bitsHost 8bD1110Multicast groupE1111Reserved / experimentalDefault masks and ranges (1st octet):A 1-126 /8 255.0.0.0B 128-191 /16 255.255.0.0C 192-223 /24 255.255.255.0D 224-239 multicast, no maskE 240-255 experimental⚠️ Exam Traps & Viva Favorites① Why subtract 2 hosts?All-zero host bits is the network ID andall-one host bits is the directed broadcast.Neither can be given to a host.② Limit of classful?Fixed block sizes waste addresses. CIDR allowscustom prefixes such as /23 for 300 hosts andreplaced classes in 1993.③ What is 127.0.0.1?Loopback: packets go back to the local stackand never reach the wire. Used to test thesoftware network stack.Tip: AND for network, OR for broadcastMaster Revision Table(learn it row by row!)ClassLeading bits1st octetDefault maskHosts per networkUseA01 - 126255.0.0.0 (/8)16,777,214 (2^24 - 2)Huge organizationsB10128 - 191255.255.0.0 (/16)65,534 (2^16 - 2)UniversitiesC110192 - 223255.255.255.0 (/24)254 (2^8 - 2)Small LANsD1110224 - 239NoneNot applicableMulticastE1111240 - 255NoneNot applicableExperimental/27 maskPrefix 27255.255.255.2245 host bits2^5 - 2 = 30 hosts8 per 256 blockQUICK FACTSNetworks: A 2^7 = 128 · B 2^14 = 16,384 · C 2^21 = 2,097,152Subnets created = 2^s · addresses per subnet = 2^h · usable = 2^h - 2Class A 1-126 (127 is loopback) · block size = 256 - mask octetVERIFIED★ Golden rule: network = IP AND mask,usable hosts = 2^h minus two.

Logical Addressing: IPv4

1. Fundamentals of IPv4 Addressing

An IPv4 Address is a 32-bit logical identifier that uniquely and universally defines the connection of a host or router interface to the global Internet.

  • Address Space: Total possible addresses = 232=4,294,967,2962^{32} = 4{,}294{,}967{,}296 (≈4.3 billion\approx 4.3\text{ billion}).
  • Notations:
    • Binary Notation: 32 bits divided into four 8-bit octets:
      11000000.10101000.00000001.00000001
    • Dotted-Decimal Notation: Each octet is converted to decimal (0−2550 - 255) separated by dots:
      192.168.1.1
MermaidDiagram
Rendering diagram…

2. Classful Addressing

Originally, the IPv4 address space was divided into 5 discrete classes (Classes A through E):

SVGVector Architecture Diagram (SVG)
Class A: 0 Network ID (7 bits) Host ID (24 bits) /8 Class B: 10 Network ID (14 bits) Host ID (16 bits) /16 Class C: 110 Network ID (21 bits) Host (8b) /24 Class D: 1110 Multicast Group Address (28 bits) Class E: 1111 Reserved for Experimental / Future Use (28 bits)

Detailed Breakdown of Classes:

Class Leading Bits 1st Octet Range Default Subnet Mask Max Networks Hosts per Network Primary Use Case
A 0... 1−1261 - 126 255.0.0.0255.0.0.0 (/8) 128128 (272^7) 16,777,21416{,}777{,}214 (224−22^{24} - 2) Massive global organizations
B 10... 128−191128 - 191 255.255.0.0255.255.0.0 (/16) 16,38416{,}384 (2142^{14}) 65,53465{,}534 (216−22^{16} - 2) Universities & mid-size enterprises
C 110... 192−223192 - 223 255.255.255.0255.255.255.0 (/24) 2,097,1522{,}097{,}152 (2212^{21}) 254254 (28−22^8 - 2) Small businesses & home LANs
D 1110... 224−239224 - 239 None — — Multicasting
E 1111... 240−255240 - 255 None — — Experimental & Research

3. Special-Purpose IPv4 Addresses

  1. Network Address (Network ID): Host bits all zeros (0). Represents the entire subnet (e.g., 192.168.1.0/24). Cannot be assigned to any host.
  2. Directed Broadcast Address: Host bits all ones (1). Delivers a packet to all hosts in a specific subnet (e.g., 192.168.1.255).
  3. Limited Broadcast Address: 255.255.255.255. Broadcasts to all local hosts on the immediate physical wire; never forwarded by routers.
  4. Loopback Address: 127.0.0.0/8 (typically 127.0.0.1 = localhost). Used to test local network stack software without generating physical network traffic.
  5. Private IP Addresses (RFC 1918): Unroutable on the public Internet, reserved for internal intranets behind NAT:
    • Class A: 10.0.0.0 to 10.255.255.255 (10.0.0.0/8)
    • Class B: 172.16.0.0 to 172.31.255.255 (172.16.0.0/12)
    • Class C: 192.168.0.0 to 192.168.255.255 (192.168.0.0/16)
  6. APIPA (Automatic Private IP Addressing): 169.254.0.0/16. Auto-configured by Windows/Mac clients when a DHCP server cannot be reached.

4. Subnetting & CIDR (Classless Inter-Domain Routing)

Due to rapid exhaustion of Class A and B blocks, CIDR (Classless Inter-Domain Routing) replaced rigid classful boundaries in 1993:

  • An arbitrary number of contiguous bits (nn) define the Network Prefix (written as /n slash notation).
  • Subnet Mask: A 32-bit number where the first nn bits are 1s and the remaining (32−n)(32 - n) host bits are 0s.
SVGVector Architecture Diagram (SVG)
CIDR Prefix /27 Mask 11111111 . 11111111 . 11111111 . 11100000 ===> 255.255.255.224 Network Prefix: 27 bits Host: 5 bits

Fundamental Subnetting Formulas:

For a subnet borrowing ss bits from the host field with hh remaining host bits:

Number of Subnets Created=2s\text{Number of Subnets Created} = 2^s
Total IP Addresses per Subnet=2h\text{Total IP Addresses per Subnet} = 2^h
\text{Usable Host Addresses per Subnet} = 2^h - 2 \quad (\text{Excluding Network ID & Broadcast})

5. Solved Step-by-Step Subnetting Numerical

Problem:

Given the IP address 200.10.20.75 with subnet mask 255.255.255.224 (/27):

  1. Find the Network Address.
  2. Find the Directed Broadcast Address.
  3. Find the range of usable host addresses.
  4. Calculate the total number of usable hosts in this subnet.

Solution:

  • Last octet of IP: 7510=01001011275_{10} = \mathbf{01001011}_2.
  • Last octet of Mask: 22410=111000002224_{10} = \mathbf{11100000}_2 (n=27n = 27, remaining host bits h=32−27=5h = 32 - 27 = 5).
  1. Network Address: Perform bitwise AND between IP and Mask:
01001011 AND 11100000=010000002=641001001011 \text{ AND } 11100000 = 01000000_2 = \mathbf{64}_{10}
Network Address=200.10.20.64\text{Network Address} = \mathbf{200.10.20.64}
  1. Directed Broadcast Address: Set all 5 host bits to 1:
01000000 OR 00011111=010111112=951001000000 \text{ OR } 00011111 = 01011111_2 = \mathbf{95}_{10}
Directed Broadcast=200.10.20.95\text{Directed Broadcast} = \mathbf{200.10.20.95}
  1. Usable Host Range: From (Network ID +1+ 1) to (Broadcast −1- 1):
200.10.20.65to200.10.20.94\mathbf{200.10.20.65} \quad \text{to} \quad \mathbf{200.10.20.94}
  1. Usable Hosts:
2h−2=25−2=32−2=30 hosts2^h - 2 = 2^5 - 2 = 32 - 2 = \mathbf{30\text{ hosts}}

Frequently Asked Questions

QWhy are 2 addresses subtracted when calculating usable hosts per subnet?

The first address (all host bits 0) is reserved as the Network ID, and the last address (all host bits 1) is reserved as the Directed Broadcast Address.

QWhat was the primary limitation of Classful Addressing?

Inflexible block sizes. An organization requiring 300 IP addresses was forced to obtain a Class B block (65,53465{,}534 addresses), wasting >65,000> 65{,}000 addresses (99.5%99.5\% wastage). CIDR resolved this by allowing custom prefix lengths (/23).

QWhat is the purpose of the 127.0.0.1 IP address?

It is the standard IPv4 Loopback address, redirecting transmitted packets back into the local operating system's protocol stack without touching the physical network.

QWhich IPv4 ranges are private (RFC 1918)?

10.0.0.0/8, 172.16.0.0/12 (172.16.0.0–172.31.255.255) and 192.168.0.0/16. They are not routable on the public Internet and are used behind NAT.

AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.

← All Computer Networks modules