Sub topic 1
Reading IPv4 Addresses in Binary and Dotted Decimal
Prerequisites
You should know that a network connects devices and that an IP address identifies a network interface. You should also be comfortable with decimal numbers and powers of two.
Dotted decimal and binary
An IPv4 address is a 32-bit number. It is usually written as four decimal numbers separated by periods. Each number is an octet, which contains eight bits and can range from 0 through 255.
For example, 192.168.1.10 has four octets:
192 168 1 10
11000000 10101000 00000001 00001010Each binary position represents a power of two, from 128 down to 1. Leading zeroes keep every octet at exactly eight bits.
address = "192.168.1.10"
octets = [int(part) for part in address.split(".")]
binary = ".".join(format(octet, "08b") for octet in octets)
print(binary)The structure of an IPv4 address
An address has two logical parts:
- The network part identifies the network.
- The host part identifies an interface on that network.
A subnet mask, or a CIDR prefix in modern networking, tells you where the split occurs. In the original classful system, the address class supplied the default split.
flowchart LR
A[32-bit IPv4 address] --> B[Network part]
A --> C[Host part]
D[Subnet mask or class default] --> B
D --> CThe original classful scheme
Classful addressing divided IPv4 addresses according to the first octet. Classes A, B, and C were used for ordinary unicast networks. Class D supported multicast. Class E was reserved.
| Class | First octet | Default mask | Network and host split |
|---|---|---|---|
| A | 0–127 | 255.0.0.0 (`/8`) | 8 network bits, 24 host bits |
| B | 128–191 | 255.255.0.0 (`/16`) | 16 network bits, 16 host bits |
| C | 192–223 | 255.255.255.0 (`/24`) | 24 network bits, 8 host bits |
| D | 224–239 | Not applicable | Multicast |
| E | 240–255 | Not applicable | Reserved |
Classful addressing wasted address space because networks could receive only these fixed sizes. CIDR later replaced it by allowing prefixes such as /20 and /27.
Exercise
What class is 172.16.5.4, and what was its default mask?
Show answer
It is Class B because its first octet is between 128 and 191. Its default mask was 255.255.0.0 (/16).