Skip to content

IP Addressing

IP addressing is the mechanism by which hosts are identified and located on an IP network. Every Networked device must have an IP address to participate in IP communication. This section covers IPv4 and IPv6 addressing, subnetting, NAT, DHCP, and ARP — the foundational addressing Infrastructure of the Internet.

An IPv4 address is a 32-bit number, represented in dotted decimal notation as four Octets separated by periods. Each octet represents 8 bits and ranges from 0 to 255.

192.168.1.100
Binary: 11000000.10101000.00000001.01100100
Octets: [ 192 ].[ 168 ].[ 1 ].[ 100 ]
Bits: [31 24][23 16][15 8][7 0]

The total IPv4 address space is 232=4,294,967,2962^{32} = 4,294,967,296 addresses. This was considered sufficient In the 1970s but is grossly inadequate for today”s Internet, where every smartphone, server, VM, and Container needs an address.

Working with IP addresses in binary is essential for understanding subnetting. Convert each octet:

192 = 128 + 64 = 11000000
168 = 128 + 32 + 8 = 10101000
1 = 1 = 00000001
100 = 64 + 32 + 4 = 01100100

Quick reference for binary-to-decimal conversion:

BitValueBitValueBitValueBitValue
7128664532416
38241201
AddressPurpose
0.0.0.0Unspecified source (used in DHCP requests, default route)
127.0.0.1Loopback (localhost) — packets never leave the host
255.255.255.255Limited broadcast (all hosts on the local segment)
169.254.0.0/16Link-local (APIPA — automatic when DHCP fails)
224.0.0.0/4Multicast (224.0.0.0-239.255.255.255)
240.0.0.0/4Reserved (formerly Class E, 240.0.0.0-255.255.255.255)
192.0.0.0/24IETF Protocol Assignments
192.0.2.0/24Documentation (RFC 5737, TEST-NET-1)
198.51.100.0/24Documentation (RFC 5737, TEST-NET-2)
203.0.113.0/24Documentation (RFC 5737, TEST-NET-3)

Before CIDR (Classless Inter-Domain Routing), IPv4 addresses were divided into five classes:

ClassFirst Octet RangeNetwork BitsHost BitsDefault Subnet MaskUsable Hosts
A0-127824255.0.0.0 (/8)16,777,214
B128-1911616255.255.0.0 (/16)65,534
C192-223248255.255.255.0 (/24)254
D224-239N/AN/AN/A (multicast)N/A
E240-255N/AN/AN/A (reserved)N/A

The class was determined by the first few bits of the first octet:

Class A: 0xxxxxxx (0-127)
Class B: 10xxxxxx (128-191)
Class C: 110xxxxx (192-223)
Class D: 1110xxxx (224-239)
Class E: 1111xxxx (240-255)

Classful addressing was wasteful. A company needing 300 hosts would receive a Class B (65,534 Hosts), wasting 65,234 addresses. A company needing 5 hosts would receive a Class C (254 hosts), Wasting 249 addresses. This inefficiency drove the adoption of CIDR in 1993 (RFC 1519).

Classful addressing is obsolete. Modern networks use CIDR notation exclusively. However, classful Boundaries are still referenced in documentation and some legacy systems, so understanding them is Necessary.

CIDR (Classless Inter-Domain Routing) expresses a network as an IP address followed by a slash and The number of network bits (the prefix length):

192.168.1.0/24 -- 24 network bits, 8 host bits
10.0.0.0/8 -- 8 network bits, 24 host bits
172.16.0.0/12 -- 12 network bits, 20 host bits

The prefix length defines the boundary between the network portion and the host portion of the Address. The subnet mask is the binary representation of this boundary.

A /24 prefix means the first 24 bits are network bits. In binary: 11111111.11111111.11111111.00000000 = 255.255.255.0.

CIDRSubnet MaskBinary
/8255.0.0.011111111.00000000.00000000.00000000
/12255.240.0.011111111.11110000.00000000.00000000
/16255.255.0.011111111.11111111.00000000.00000000
/20255.255.240.011111111.11111111.11110000.00000000
/24255.255.255.011111111.11111111.11111111.00000000
/25255.255.255.12811111111.11111111.11111111.10000000
/28255.255.255.24011111111.11111111.11111111.11110000
/30255.255.255.25211111111.11111111.11111111.11111100
/32255.255.255.25511111111.11111111.11111111.11111111

The number of addresses in a CIDR block is 2^{32 - \mathrm{prefix length}. The number of usable Host addresses is 2^{32 - \mathrm{prefix length} - 2 (subtract the network address and broadcast Address). The exception is /31 (point-to-point links per RFC 3021) where both addresses are usable, And /32 which represents a single host.

Subnetting divides a network into smaller sub-networks (subnets). This improves network efficiency, Reduces broadcast domains, and provides better security boundaries.

To subnet a network, borrow bits from the host portion to create additional network bits.

Example: Subnet 192.168.1.0/24 into 4 subnets

  1. Determine how many bits to borrow: 2n42^n \ge 4So n=2n = 2 bits
  2. New prefix length: /24 + 2 = /26
  3. New subnet mask: 255.255.255.192
  4. Subnet size: 23226=26=642^{32-26} = 2^6 = 64 addresses per subnet (62 usable, minus network and broadcast)
Subnet 0: 192.168.1.0/26 (192.168.1.0 - 192.168.1.63)
Subnet 1: 192.168.1.64/26 (192.168.1.64 - 192.168.1.127)
Subnet 2: 192.168.1.128/26 (192.168.1.128 - 192.168.1.191)
Subnet 3: 192.168.1.192/26 (192.168.1.192 - 192.168.1.255)

For each subnet:

  • Network address: all host bits are 0 (first address)
  • Broadcast address: all host bits are 1 (last address)
  • First usable host: network address + 1
  • Last usable host: broadcast address - 1
  • Usable hosts: all addresses between network and broadcast
10.0.0.0/16 available
Needs:
- 1 subnet with 4000 hosts -> /20 (4094 usable)
- 4 subnets with 500 hosts -> /22 (1022 usable each)
- 8 subnets with 200 hosts -> /24 (254 usable each)
Allocation:
10.0.0.0/20 (10.0.0.0 - 10.0.15.255) -- 4000 hosts
10.0.16.0/22 (10.0.16.0 - 10.0.19.255) -- 500 hosts
10.0.20.0/22 (10.0.20.0 - 10.0.23.255) -- 500 hosts
10.0.24.0/22 (10.0.24.0 - 10.0.27.255) -- 500 hosts
10.0.28.0/22 (10.0.28.0 - 10.0.31.255) -- 500 hosts
10.0.32.0/24 (10.0.32.0 - 10.0.32.255) -- 200 hosts
10.0.33.0/24 (10.0.33.0 - 10.0.33.255) -- 200 hosts
10.0.34.0/24 (10.0.34.0 - 10.0.34.255) -- 200 hosts
10.0.35.0/24 (10.0.35.0 - 10.0.35.255) -- 200 hosts
10.0.36.0/24 (10.0.36.0 - 10.0.36.255) -- 200 hosts
10.0.37.0/24 (10.0.37.0 - 10.0.37.255) -- 200 hosts
10.0.38.0/24 (10.0.38.0 - 10.0.38.255) -- 200 hosts
10.0.39.0/24 (10.0.39.0 - 10.0.39.255) -- 200 hosts