Advanced IP Addressing and Subnetting
IPv4 Binary Mechanics
From Dots and Decimals to Binary
You're used to seeing an IPv4 address as four numbers separated by dots, like 172.16.254.1. To a computer, this is just a single 32-bit integer. Each of the four numbers, called an octet, represents 8 bits of that 32-bit total. Understanding this binary foundation is key to grasping how routing and network segmentation actually work.
Let's break down an IP address. The address 192.168.1.10 is simple for us to read, but a router sees its binary equivalent. Each octet is converted from decimal to its 8-bit binary form.
192becomes11000000168becomes101010001becomes0000000110becomes00001010
Stitched together, the 32-bit address is 11000000101010000000000100001010.
Knowing how to convert between decimal and binary is the first step. The next is understanding how a network device interprets this 32-bit number.
The Subnet Mask's Role
An IP address has two parts: a network ID and a host ID. The network ID is like a street name, identifying which network the device is on. The host ID is like a house number, unique to that device on the network.
A is what tells a router where the network portion ends and the host portion begins. It's a 32-bit number, just like an IP address, but its structure is simpler: a sequence of 1s followed by a sequence of 0s. The 1s "mask" the network portion, and the 0s leave the host portion unmasked.
For example, a common subnet mask is 255.255.255.0. In binary, this is 24 ones followed by 8 zeros: 11111111.11111111.11111111.00000000. This is often written in as /24, which is just a count of the leading 1 bits.
To find the network ID, a router performs a operation, which you'll recognize from C programming as the & operator. It compares the bits of the IP address and the subnet mask one by one.
Why Classful Addressing Faded
Before CIDR, the internet used a system called classful addressing. This system divided all IPv4 addresses into a few fixed-size classes, primarily A, B, and C. The class was determined by the first few bits of the address.
| Class | Leading Bits | Default Mask (CIDR) | Host Addresses |
|---|---|---|---|
| Class A | 0... | /8 (255.0.0.0) | 16,777,214 |
| Class B | 10... | /16 (255.255.0.0) | 65,534 |
| Class C | 110... | /24 (255.255.255.0) | 254 |
The problem was its incredible inefficiency. If an organization needed 300 IP addresses, a Class C block (254 hosts) was too small. They were forced to get a Class B block, which provided over 65,000 addresses. This wasted thousands of addresses that couldn't be used by anyone else.
Classless Inter-Domain Routing (CIDR) solved this by detaching the subnet mask size from the IP address itself. It introduced Variable Length Subnet Masking (VLSM), allowing network administrators to define masks of any length. This lets them create subnets that are precisely sized for the number of hosts they need, eliminating waste and making the entire internet more scalable.
An IPv4 address is fundamentally a single integer of what length?
What is the 8-bit binary representation of the decimal number 168?