The global internet connects billions of heterogeneous devices. To achieve seamless end-to-end communication, IP addresses must be unique, universal, and dynamically routable across multiple network boundaries.
An IPv4 address is a 32-bit identifier that uniquely and universally defines the connection of a host or router interface to the Internet. The theoretical pool of addresses available is:
Historically, this address space was divided into rigid classes (Classes A, B, C, D, and E) under the system known as Classful Addressing. However, this model caused massive address depletion due to structural inefficiencies:
To address the rapid depletion of IPv4 addresses, the Internet Engineering Task Force (IETF) introduced Classless Addressing (CIDR) in the mid-1990s. In CIDR, the division between network identifier (prefix) and host identifier (suffix) is variable and represented in slash notation (or CIDR notation), written as:
where is the prefix length (representing the number of continuous bits set to 1 in the network mask).
32-bit IP Address:
+------------------------------------+------------------------------------+
| Prefix (n bits) | Suffix (32 - n bits) |
+------------------------------------+------------------------------------+
| Identifies the Network Block | Identifies the Host on Network |
+------------------------------------+------------------------------------+In classless routing, three essential properties define a given block:
The Number of Addresses in the Block ():
The First Address (Network Address): Found by performing a bitwise logical AND operation between the given IP address and the network mask.
Consider an IP address in classless notation: 110.23.120.14/20. Let us calculate the block properties:
Find Prefix and Suffix:
Subnetting is the process of dividing a large block of addresses into smaller, distinct sub-blocks (subnets). In CIDR, subnetting is flexible; we can customize subnet boundaries dynamically using Variable-Length Subnet Masking (VLSM).
When an organization is granted a block of addresses, it must allocate addresses to its subnets under strict mathematical constraints:
The number of addresses allocated to any subnet must be a power of 2 ().
The subnet mask prefix length is determined by:
An ISP is allocated a classless block of addresses starting at 190.100.0.0/16 ( addresses). It needs to partition these addresses among three groups of customers:
[ ISP Block: 190.100.0.0/16 ]
|
+-----------------------+-----------------------+
| | |
[ Group 1 Subblock ] [ Group 2 Subblock ] [ Group 3 Subblock ]
64 Customers 128 Customers 128 Customers
Each gets /24 Each gets /25 Each gets /26Let us design the hierarchical allocation:
Requested: 64 customers 256 addresses each = 16,384 addresses.
Subnet Prefix for Group 1 Block:
Requested: 128 customers 128 addresses each = 16,384 addresses.
Subnet Prefix for Group 2 Block:
The next available block starts at 190.100.64.0.
Requested: 128 customers 64 addresses each = 8,192 addresses.
Subnet Prefix for Group 3 Block:
The next available block starts at 190.100.128.0.
Certain IPv4 ranges are reserved for special purposes and cannot be assigned to standard host interfaces on the open Internet.
| Address / Block | Name | Description / Use Case |
| :--- | :--- | :--- |
| 0.0.0.0/32 | This Host (All-Zeros) | Used as a source address by a host during bootstrapping (obtaining an IP via DHCP). |
| 255.255.255.255/32 | Limited Broadcast | Sent to all hosts on the local network. Routers never forward these packets. |
| 127.0.0.0/8 | Loopback Address | Used to test local IP software implementations. Packets never leave the host. |
| 169.254.0.0/16 | Link-Local (APIPA) | Self-assigned IP when a dynamic configuration server (DHCP) is unreachable. |
| 224.0.0.0/4 | Multicast Addresses | Reserved for Class D multicast group communications. |
| 240.0.0.0/4 | Reserved Space | Reserved for future/experimental use (formerly Class E). |
Loopback Diagnostics Flow:
+------------------ Host PC -------------------+
| Application (Ping 127.0.0.1) |
| | |
| v |
| Network Layer (IP Protocol Block) |
| | (Intercepted! Address starts with 127) |
| +---------> [ Loopback Path ] |
| | |
| v |
| Application Receiver Layer |
+----------------------------------------------+
(Packet never touches the Network Interface Card / Physical Wire)A Directed Broadcast Address is formed when the network suffix bits are all set to 1. For example, in a local subnet of 192.168.1.0/24, the directed broadcast address is 192.168.1.255.
To prevent IPv4 exhaust, private networks use designated non-routable IP addresses internally. These are defined under RFC 1918:
10.0.0.0 to 10.255.255.255 (10.0.0.0/8)172.16.0.0 to 172.31.255.255 (172.16.0.0/12)192.168.0.0 to 192.168.255.255 (192.168.0.0/16)Since private IP addresses are non-routable on the public Internet, a gateway device must translate these private IP addresses into publicly routable addresses. This process is called Network Address Translation (NAT).
+----------------------- PRIVATE SITE -----------------------+
| Internal Host: 192.168.1.20 |
| |
| [Packet] Source IP: 192.168.1.20, Destination IP: 8.8.8.8 |
+-----------------------------+------------------------------+
|
v
+-------------------------------+
| NAT / Gateway Router |
| Public Interface: 203.0.113.1|
| Private Interface: 192.168.1.1|
+---------------+---------------+
|
| (Translates Source IP to Public)
v
+------------------------ PUBLIC WAN ------------------------+
| Internet Target Host: 8.8.8.8 |
| |
| [Packet] Source IP: 203.0.113.1, Destination IP: 8.8.8.8 |
+------------------------------------------------------------+When a packet leaves the private network, the NAT-enabled router intercepts the outbound IP packet. It performs the following modifications:
When a reply arrives at the NAT router from the public internet, the router performs the reverse operation:
NAT operates in three main configurations: Static NAT, Dynamic NAT, and Port-based Network Address Translation (NAPT).
In Static NAT, every internal private IP address is statically mapped to a dedicated public IP address. This is typically used for local servers (such as mail or web servers) that need to be reachable from outside the network.
In Dynamic NAT, the router maintains a pool of public IP addresses. When an internal host requests a connection to the internet, it is temporarily assigned an available public IP address from the pool.
Port Address Translation (PAT), also known as Many-to-One NAT, allows multiple internal hosts to share a single public IP address. It achieves this by tracking both IP addresses and transport layer Port Numbers.
NAPT Translation Process:
-------------------------
Outbound Packet from Host A:
[Src IP: 192.168.1.20 | Src Port: 5021] ---> [NAT Router] ---> Public: [Src IP: 203.0.113.1 | Src Port: 12001]
Outbound Packet from Host B:
[Src IP: 192.168.1.30 | Src Port: 5021] ---> [NAT Router] ---> Public: [Src IP: 203.0.113.1 | Src Port: 12002]To resolve collisions when two different internal hosts use the same source port number, the NAT router maps the private port number to a unique public port number.
The NAPT router maintains a translation table to route packets back to the correct internal hosts.
| Private Source IP | Private Source Port | Public NAT IP | Public NAT Port | Destination IP | Destination Port |
| :--- | :--- | :--- | :--- | :--- | :--- |
| 192.168.1.20 | 5021 | 203.0.113.1 | 12001 | 8.8.8.8 | 80 |
| 192.168.1.30 | 5021 | 203.0.113.1 | 12002 | 8.8.8.8 | 80 |
| 192.168.1.40 | 3000 | | | | |
When a packet arrives from the destination host 8.8.8.8 with port 80 to the destination IP 203.0.113.1 with port 12002, the router looks up the port 12002 in its table. It finds that the packet belongs to the internal host 192.168.1.30 at port 5021, translates the destination fields, and forwards the packet.
127.0.0.0/8 loopback block, 255.255.255.255/32 limited broadcast, and RFC 1918 private address ranges) help organize networks and isolate local traffic.A flexible IP address allocation scheme that replaces the rigid classful boundaries (A, B, C) with variable-length network prefixes.
The technique of dividing an allocated block of IP addresses into subnets of varying sizes to match physical topologies and prevent address waste.
Dedicated IPv4 blocks reserved for specific diagnostic, local, or administrative functions such as loopback testing and local broadcasting.
A mechanism that maps private local IP addresses to a single or small pool of public IP addresses, conserving the global IPv4 address space.
An extension of NAT that multiplexes multiple internal private IP addresses onto a single public IP address by assigning unique source port numbers.
Test your understanding with 5 questions
An organization is assigned the classless address block 192.168.10.64/26. What is the range of usable host addresses in this network block?
If a packet is sent with a destination address of 127.15.20.1, which layer of the TCP/IP suite intercepts it and diverts it back to the sender?
Which of the following address ranges belongs to the RFC 1918 private address allocation for Class B networks?
In a network using Port-based NAT (NAPT), how does the NAT-enabled router uniquely identify and route incoming reply packets from a single public web server back to multiple distinct internal hosts?
A router receives an IP packet from an external internet network with a destination address of 255.255.255.255. What action will the router take with this packet?
The Last Address (Broadcast Address): Found by performing a bitwise logical OR of the given IP address with the bitwise complement (NOT) of the network mask.
Construct Network Mask: The first 20 bits are 1s, and the remaining 12 bits are 0s.
Calculate First Address: We convert the 3rd byte of the IP address () and the 3rd byte of the mask () into binary: Thus, the First Address is:
Calculate Last Address:
Take the bitwise complement of the network mask:
Apply the bitwise OR with the network address:
Thus, the Last Address is:
The starting address of any sub-block must be evenly divisible by the size of that sub-block.
Block Range: 190.100.0.0/18 to 190.100.63.255/18.
Individual Customer Sub-block: Each customer gets a /24 prefix (256 addresses).
190.100.0.0/24190.100.1.0/24190.100.63.0/24Block Range: 190.100.64.0/18 to 190.100.127.255/18.
Individual Customer Sub-block: Each customer gets a /25 prefix (128 addresses).
190.100.64.0/25190.100.64.128/25190.100.65.0/25190.100.127.128/25Block Range: 190.100.128.0/19 to 190.100.159.255/19.
Individual Customer Sub-block: Each customer gets a /26 prefix (64 addresses).
190.100.128.0/26190.100.128.64/26190.100.159.192/26190.100.160.0190.100.255.25512003140.21.4.9236 Modules
6 Modules