Lesson 07 / 18
IPv4 Addressing
The structure of the 32-bit address, the split between network and host portions, the legacy of classful addressing, and blocks reserved for special purposes.
Contents
The previous two lessons used IP addresses like labels: 192.168.10.196 was written, it
was said which device it pointed to, but the number itself was not decoded. Yet inside
this number is a structure that routing depends on.
This lesson’s question is what that structure is: which part of the 32 bits points to the network, which part to the host within that network, and who determines this split?
The Structure of the Address
An IPv4 address is a 32-bit unsigned integer. For readability it is split into four bytes, each byte written in decimal, with dots placed between them — this is called dotted decimal notation. The notation is a convenience; the address itself is a bit string.
import ipaddress address = ipaddress.ip_address("192.168.10.196") print("integer :", int(address)) print("binary :", format(int(address), "032b")) print("byte-wise :", " ".join(f"{b:08b}" for b in address.packed)) print("hex :", address.packed.hex())
integer : 3232238276 binary : 11000000101010000000101011000100 byte-wise : 11000000 10101000 00001010 11000100 hex : c0a80ac4
The four bytes’ values are read directly: 11000000 = 192, 10101000 = 168,
00001010 = 10, 11000100 = 196. The base conversions are a direct application of the
method built up in the Binary Number System and Hexadecimal and Octal Bases lessons of
the How Computers Work course.
The total number of addresses is . This number falling short against the number of endpoint devices in the world is the reason many mechanisms covered in this course — address translation, variable-length subnets, IPv6 — exist at all.
Network and Host Portion
An address is not a single-piece identity; it splits into two portions:
- Network portion: the left-hand bits. Says which network the address belongs to. The same across every address on that network.
- Host portion: the right-hand bits. Distinguishes the address within that network.
The split point is stated by the prefix length, written after the address with a
slash: in the notation 192.168.10.196/24, the left-hand 24 bits specify the network,
the remaining 8 bits the host.
| Notation | Network portion | Host portion |
|---|---|---|
192.168.10.196/24 |
11000000 10101000 00001010 |
11000100 |
192.168.10.196/27 |
11000000 10101000 00001010 110 |
00100 |
The same address belongs to different networks with different prefix lengths. This produces a very important consequence: an address by itself is incomplete information. Configuring an interface requires giving the address and the prefix length together; if either is missing, which destinations are local cannot be determined.
The split’s counterpart in routing is direct. Routers know networks, not individual hosts. A row in a routing table maps a prefix to a next hop; the number of rows in the table is proportional to the number of networks, not the number of hosts. This is why addresses are distributed hierarchically.
The Legacy of Classful Addressing
IPv4 addresses were originally split into classes: the boundary between network and host was determined by looking at the address’s first bits.
| Class | First bits | Address range | Network portion | Hosts per network |
|---|---|---|---|---|
| A | 0 |
0.0.0.0 – 127.255.255.255 | 8 bits | 16,777,214 |
| B | 10 |
128.0.0.0 – 191.255.255.255 | 16 bits | 65,534 |
| C | 110 |
192.0.0.0 – 223.255.255.255 | 24 bits | 254 |
| D | 1110 |
224.0.0.0 – 239.255.255.255 | Multicast | — |
| E | 1111 |
240.0.0.0 – 255.255.255.255 | Reserved | — |
This scheme had two flaws. First, the boundary being able to take only three values led to address waste: a class C is not enough for a 300-host organization, and giving it a class B wastes 65,234 addresses. Second, the size of routing tables could not be controlled: every network needed its own row, and rows could not be merged.
The solution was to make the boundary independent of the address. With classless inter-domain routing (CIDR), the prefix length is carried explicitly alongside the address and can take any value from 0 to 32. Classes are no longer used in address allocation; but the traces they left remain — some tools’ default mask suggestions and the phrase “class C network” in some documents come from this legacy.
This course takes classless notation as the basis. Class names are mentioned only for historical context.
Special-Purpose Blocks
Part of the address space is set aside to never be routed on the public internet.
| Block | Purpose | Routed on the public internet? |
|---|---|---|
10.0.0.0/8 |
Private use | No |
172.16.0.0/12 |
Private use | No |
192.168.0.0/16 |
Private use | No |
127.0.0.0/8 |
Loopback (own machine) | No |
169.254.0.0/16 |
Link-local (when no address can be obtained) | No |
100.64.0.0/10 |
Carrier-grade NAT | No |
224.0.0.0/4 |
Multicast | Conditional |
255.255.255.255 |
Limited broadcast | No |
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 |
Documentation | No |
The three private use blocks can be used freely on internal organizational networks. Different organizations can use the same private addresses at the same time; there is no collision, because these addresses never leave the organization. Going outward is provided by address translation, the subject of the NAT and PAT lesson.
The loopback block refers to the machine itself; a packet sent to this block never reaches the network interface. The link-local block is for the temporary address an interface chooses for itself when it cannot obtain an address; this address can only reach other devices on the same network.
The documentation blocks are used throughout this course wherever an example needs a
public address. The organization’s external address, 203.0.113.10, and the destination
server, 198.51.100.20, come from these blocks.
import ipaddress for text in ("10.0.0.1", "127.0.0.1", "169.254.7.3", "224.0.0.251", "192.168.10.196", "198.51.100.20"): addr = ipaddress.ip_address(text) print(f"{text:16s} private={str(addr.is_private):5s} loopback={str(addr.is_loopback):5s} " f"link_local={str(addr.is_link_local):5s} multicast={addr.is_multicast}")
10.0.0.1 private=True loopback=False link_local=False multicast=False 127.0.0.1 private=True loopback=True link_local=False multicast=False 169.254.7.3 private=True loopback=False link_local=True multicast=False 224.0.0.251 private=False loopback=False link_local=False multicast=True 192.168.10.196 private=True loopback=False link_local=False multicast=False 198.51.100.20 private=True loopback=False link_local=False multicast=False
The last row deserves attention: 198.51.100.20 is a documentation address, not in the
private use block; yet is_private still returns true. This property does not answer
“is it in the private use block,” but “is it routable on the public internet.”
Differences like this between a library property’s name and its meaning make reading the
documented meaning mandatory.
Who an Address Belongs To
An IP address belongs not to a machine but to an interface. A machine with two
interfaces has two addresses; more than one address can also be assigned to the same
interface. Routers are the clearest example of this rule: on the example network, the
organization’s router carries 192.168.10.193 on its internal interface and
203.0.113.10 on its external interface, and these two addresses belong to different
networks.
This distinction helps in diagnosis. “I cannot reach the server” is incomplete; which of the server’s interfaces cannot be reached must be asked. A machine reachable through one interface can be unreachable through another.
The Example Network’s Block
The organization’s internal network uses the 192.168.10.0/24 block. The reasons for
the choice are these:
- The block is in the private use range; it requires no allocation from a provider.
- A 24-bit prefix leaves an 8-bit host portion: addresses.
- Two of these 256 addresses are reserved — the lowest denotes the network itself, the highest the broadcast address — leaving 254 usable addresses.
The organization’s sections have 182 hosts in total: 100 on the guest wireless network, 50 in the lab, 20 in administration, 10 in the server room, and 2 on the point-to-point link between routers. Since that number is less than 254, the block is sufficient — but the sections cannot be gathered into a single broadcast domain.
Why they cannot be gathered was seen in the previous lesson: as a broadcast domain grows, the cost of every broadcast frame rises, and no access control can be established between sections. The block needs to be split into sections.
Summary
- An IPv4 address is a 32-bit integer; dotted decimal notation is only for readability.
- The address splits into network and host portions; the boundary is stated by the prefix length and cannot be read from the address alone.
- Without a prefix length, an address is incomplete information; which destinations are local cannot be determined.
- Classful addressing confined the boundary to three values and led to waste; CIDR freed the prefix length to any value from 0 to 32.
- Private use, loopback, link-local, multicast, and documentation blocks are not routed on the public internet.
- An address belongs to an interface, not a machine; a machine can have more than one address.
Next Step
The 192.168.10.0/24 block cannot be handed to the organization’s sections as a single
piece. The block has to be cut so each section gets a separate network, and the cutting
is done by borrowing bits from the host portion. The next lesson builds up mask
arithmetic, shows how network and broadcast addresses are computed, and produces the
first plan that splits the block into equal parts.
To keep your progress and take notes, Log in
My notes
Log in to take notes.