Showing raw Markdown: the renderer could not load.
## Why this matters
You work from home and connect to two Virtual Private Networks (VPNs): one for your employer and one for a client. Both use `192.168.1.0/24` internally, and so does your home router. Suddenly half the client's servers are unreachable, and your printer has vanished. Nothing is broken. Your laptop simply has three routes to "the same" network and can only pick one.
Or a colleague says: "The new server has no internet." You log in and see the address `169.254.83.17`. If you can read that number, you already know the cause: the server never got an answer from a Dynamic Host Configuration Protocol (DHCP) server and gave itself a fallback address. IP addresses carry a lot of information. This lesson teaches you to read it.
## Learning objectives
- Explain what an IP address identifies, how it differs from a MAC address, and how an IPv4 address is split into network and host parts with a prefix length (Classless Inter-Domain Routing, CIDR, notation).
- Convert IPv4 addresses and masks between dotted-decimal and binary, and work out the network address, broadcast address and usable host range of a given prefix.
- Classify IPv4 addresses by purpose: public, private (RFC 1918), loopback, link-local, shared address space for Carrier-Grade NAT (RFC 6598), documentation (RFC 5737), multicast and broadcast.
- Explain why IPv6 exists and recognize an IPv6 address and its prefix length.
- Compare static addressing with the Dynamic Host Configuration Protocol (DHCP), and explain why private addressing and network address translation (NAT) exist.
## Key concepts
### What an IP address identifies
Think of a postal address. "Flat 3, 12 High Street, Leeds" tells the post office *where* you are, not *who* you are. If you move, you get a new address. Your name stays the same.
An **Internet Protocol (IP) address** works the same way. It identifies a network interface *and where it sits*: which network it belongs to, and which host it is on that network. Routers use the network part to forward packets towards the right network, hop by hop (Layer 3 in the [OSI model](../04-osi-model/lesson.md)).
A **Media Access Control (MAC) address** is different. It is a 48-bit identifier, usually burned into the network card, used only to deliver frames on the local link (Layer 2). It says nothing about location.
| | IP address | MAC address |
|---|---|---|
| OSI layer | 3 (Network) | 2 (Data Link) |
| Size | 32 bits (IPv4), 128 bits (IPv6) | 48 bits |
| Written as | `192.0.2.130` | `00:00:5e:00:53:82` |
| Assigned by | Network administrator or DHCP; depends on the network you join | Manufacturer (operating systems can randomize it) |
| Scope | End to end, across many networks | One link only; rewritten at every router |
| Has a network part? | Yes | No |
<figure class="diagram" style="--dg-w: 940px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 940 300" width="940" height="300" role="img" aria-labelledby="ip-hop-by-hop-title ip-hop-by-hop-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ip-hop-by-hop-title">IP addresses stay, MAC addresses change at every hop</title>
<desc id="ip-hop-by-hop-desc">A laptop at 192.0.2.10 sends a packet to a server at 203.0.113.80 through routers R1 and R2. Frame 1 goes from the laptop's MAC to R1's MAC, frame 2 from R1's MAC to R2's MAC, and frame 3 from R2's MAC to the server's MAC. The IP packet inside, from 192.0.2.10 to 203.0.113.80, stays the same end to end.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="939" height="299" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<rect class="dg-card" x="40" y="40" width="140" height="96" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(56 56) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="98" y="77" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Laptop</text>
<text x="58" y="108" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.10</text>
<rect class="dg-card" x="280" y="40" width="140" height="76" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(296 56) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="338" y="77" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Router R1</text>
<rect class="dg-card" x="520" y="40" width="140" height="76" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(536 56) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="578" y="77" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Router R2</text>
<rect class="dg-card" x="760" y="40" width="140" height="96" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(776 56) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="2" rx="2"/><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6 6h.01"/><path d="M6 18h.01"/></g>
<text x="818" y="77" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Server</text>
<text x="778" y="108" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<g class="dg-l2"><path class="dg-stroke" d="M180 78H276" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><path class="dg-stroke" d="M269 72l8 6-8 6" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><rect class="dg-solid" x="193" y="160" width="74" height="26" rx="13" fill="#15803d"/><text x="230" y="177.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Frame 1</text></g>
<text x="230" y="206" font-size="12" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">MAC laptop → MAC R1</text>
<g class="dg-l2"><path class="dg-stroke" d="M230.0 86V154" stroke="#15803d" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-l2"><path class="dg-stroke" d="M420 78H516" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><path class="dg-stroke" d="M509 72l8 6-8 6" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><rect class="dg-solid" x="433" y="160" width="74" height="26" rx="13" fill="#15803d"/><text x="470" y="177.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Frame 2</text></g>
<text x="470" y="206" font-size="12" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">MAC R1 → MAC R2</text>
<g class="dg-l2"><path class="dg-stroke" d="M470.0 86V154" stroke="#15803d" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<g class="dg-l2"><path class="dg-stroke" d="M660 78H756" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><path class="dg-stroke" d="M749 72l8 6-8 6" stroke="#15803d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l2"><rect class="dg-solid" x="673" y="160" width="74" height="26" rx="13" fill="#15803d"/><text x="710" y="177.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Frame 3</text></g>
<text x="710" y="206" font-size="12" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">MAC R2 → MAC server</text>
<g class="dg-l2"><path class="dg-stroke" d="M710.0 86V154" stroke="#15803d" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/></g>
<text x="470" y="230" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="middle">New frame on every link: MAC addresses change at each router</text>
<g class="dg-l3"><rect class="dg-solid" x="40" y="246" width="860" height="34" rx="10" fill="#b45309"/><text x="470" y="268" font-size="13" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">IP packet inside every frame: 192.0.2.10 → 203.0.113.80 · unchanged end to end</text></g>
</svg></figure>
*Figure 1. The packet keeps source `192.0.2.10` and destination `203.0.113.80` end to end. Each link uses a new frame with new MAC addresses.*
> [!CHECK]
> You carry your laptop from home to the office and plug it in. Why does it need a different IP address there?
>
> - [ ] Because its MAC address changes when it joins a new network
> - [x] Because an IP address must belong to the network the laptop is attached to, or routers can't deliver traffic back to it
> - [ ] Because IP addresses expire every time the laptop sleeps
>
> The network part of an IP address says where the host is. A home address on the office network points to the wrong place, so replies would never arrive. The MAC address identifies the card, not the location.
### Anatomy of an IPv4 address
An **IPv4 address** (RFC 791) is a 32-bit number. Computers see 32 ones and zeros. People write it in **dotted-decimal** notation: four groups of 8 bits, called **octets**, each written as a decimal number from 0 to 255 and separated by dots.
To convert an octet between decimal and binary, use the place value of each of its 8 bits:
| Bit position | 1st | 2nd | 3rd | 4th | 5th | 6th | 7th | 8th |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| `130` = 128 + 2 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| `192` = 128 + 64 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
- **Decimal to binary:** go from left to right. If the place value fits in what's left, write 1 and subtract it; otherwise write 0.
- **Binary to decimal:** add up the place values of the 1 bits.
So `192.0.2.130` is `11000000.00000000.00000010.10000010`. There are 2³² = 4,294,967,296 possible IPv4 addresses, which sounds like a lot until you remember there are billions of phones, laptops, servers and sensors.
Every IPv4 address has two parts:
- the **network part** (the leftmost bits): which network the host is on. All hosts on the same network share it.
- the **host part** (the remaining bits): which interface on that network.
The address alone doesn't tell you where the split is. That is the job of the prefix length.
> [!CHECK]
> What is `11000000.10101000.00000001.00010111` in dotted decimal?
>
> - [ ] `192.168.1.17`
> - [x] `192.168.1.23`
> - [ ] `192.164.1.23`
> - [ ] `193.168.1.23`
>
> `10101000` is 128 + 32 + 8 = 168, and `00010111` is 16 + 4 + 2 + 1 = 23. Getting 17 means adding only the 16 and 1 bits and missing the 4 and 2.
### Prefix length and subnet mask
The **prefix length** says how many leading bits are the network part. You write it after a slash: in `192.0.2.130/26`, the first 26 bits are the network and the last 6 bits are the host. This is **CIDR notation**, from **Classless Inter-Domain Routing (CIDR)**, defined today in RFC 4632.
The **subnet mask** says the same thing in dotted-decimal form: 1 for every network bit, 0 for every host bit. A `/26` is 26 ones and 6 zeros, which is `255.255.255.192`.
<figure class="diagram" style="--dg-w: 800px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 800 368" width="800" height="368" role="img" aria-labelledby="ip-address-anatomy-title ip-address-anatomy-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ip-address-anatomy-title">Anatomy of the IPv4 address 192.0.2.130/26</title>
<desc id="ip-address-anatomy-desc">The address 192.0.2.130 written as four decimal octets and as 32 bits. The prefix length /26 marks the first 26 bits as the network part and the last 6 bits as the host part. Below it, the subnet mask 255.255.255.192: 26 ones followed by 6 zeros. Setting all host bits to 0 gives the network address 192.0.2.128; setting them all to 1 gives the broadcast address 192.0.2.191. The usable host addresses run from 192.0.2.129 to 192.0.2.190, 62 in total.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="799" height="367" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<text x="23" y="34" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700" letter-spacing="1.2">IPv4 ADDRESS 192.0.2.130/26</text>
<text x="110.0" y="66" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192</text>
<text x="207.0" y="66" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="304.0" y="66" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text>
<text x="401.0" y="66" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="498.0" y="66" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text>
<text x="595.0" y="66" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="692.0" y="66" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">130</text>
<g class="dg-l1"><rect class="dg-solid" x="23" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="33.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-solid" x="45" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="55.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-solid" x="67" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="77.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="89" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="99.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="111" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="121.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="133" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="143.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="155" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="165.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="177" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="187.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="217" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="227.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="239" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="249.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="261" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="271.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="283" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="293.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="305" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="315.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="327" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="337.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="349" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="359.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="371" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="381.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="411" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="421.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="433" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="443.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="455" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="465.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="477" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="487.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="499" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="509.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="521" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="531.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="543" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="553.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-solid" x="565" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="575.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><rect class="dg-solid" x="605" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="615.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-solid" x="627" y="78" width="20" height="32" rx="4" fill="#0369a1"/><text x="637.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-solid" x="649" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="659.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-solid" x="671" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="681.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-solid" x="693" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="703.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-solid" x="715" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="725.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-solid" x="737" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="747.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l4"><rect class="dg-solid" x="759" y="78" width="20" height="32" rx="4" fill="#c2410c"/><text x="769.0" y="99.5" font-size="13" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<text x="23" y="148" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700" letter-spacing="1.2">SUBNET MASK 255.255.255.192 (/26)</text>
<text x="110.0" y="180" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">255</text>
<text x="207.0" y="180" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="304.0" y="180" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">255</text>
<text x="401.0" y="180" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="498.0" y="180" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">255</text>
<text x="595.0" y="180" font-size="20" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text>
<text x="692.0" y="180" font-size="20" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192</text>
<g class="dg-l1"><rect class="dg-tint" x="23" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="33.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="45" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="55.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="67" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="77.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="89" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="99.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="111" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="121.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="133" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="143.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="155" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="165.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="177" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="187.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="217" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="227.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="239" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="249.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="261" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="271.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="283" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="293.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="305" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="315.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="327" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="337.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="349" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="359.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="371" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="381.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="411" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="421.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="433" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="443.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="455" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="465.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="477" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="487.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="499" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="509.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="521" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="531.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="543" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="553.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="565" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="575.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="605" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="615.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l1"><rect class="dg-tint" x="627" y="192" width="20" height="32" rx="4" fill="#ebf3f7" stroke="#9ac3d9"/><text x="637.0" y="213.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g>
<g class="dg-l4"><rect class="dg-tint" x="649" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="659.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-tint" x="671" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="681.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-tint" x="693" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="703.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-tint" x="715" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="725.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-tint" x="737" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="747.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l4"><rect class="dg-tint" x="759" y="192" width="20" height="32" rx="4" fill="#faf0ec" stroke="#e7b39e"/><text x="769.0" y="213.5" font-size="13" class="dg-ink" fill="#c2410c" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M24 230V238H646V230" stroke="#0369a1" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/><text x="335.0" y="258" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle">Network part · 26 bits</text></g>
<g class="dg-l4"><path class="dg-stroke" d="M650 230V238H778V230" stroke="#c2410c" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/><text x="714.0" y="258" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle">Host part · 6 bits</text></g>
<rect class="dg-card" x="23.0" y="284" width="242.0" height="62" rx="10" fill="#ffffff" stroke="#e3e3dd"/>
<text x="37.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600">Network address</text>
<text x="37.0" y="328" font-size="15" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.128</text>
<text x="251.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">host bits all 0</text>
<rect class="dg-card" x="279.0" y="284" width="242.0" height="62" rx="10" fill="#ffffff" stroke="#e3e3dd"/>
<text x="293.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600">Broadcast address</text>
<text x="293.0" y="328" font-size="15" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.191</text>
<text x="507.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">host bits all 1</text>
<rect class="dg-card" x="535.0" y="284" width="242.0" height="62" rx="10" fill="#ffffff" stroke="#e3e3dd"/>
<text x="549.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600">Usable hosts</text>
<text x="549.0" y="328" font-size="15" class="dg-text" fill="#17171c" font-weight="600" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.0.2.129 – .190</text>
<text x="763.0" y="304" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">62 addresses</text>
</svg></figure>
*Figure 2. `192.0.2.130/26`: 26 network bits (blue) and 6 host bits (orange). The mask has a 1 above every network bit.*
Common prefixes are worth memorizing:
| Prefix | Subnet mask | Host bits | Usable hosts (2ʰ − 2) |
|---|---|---|---|
| `/8` | `255.0.0.0` | 24 | 16,777,214 |
| `/16` | `255.255.0.0` | 16 | 65,534 |
| `/24` | `255.255.255.0` | 8 | 254 |
| `/25` | `255.255.255.128` | 7 | 126 |
| `/26` | `255.255.255.192` | 6 | 62 |
| `/27` | `255.255.255.224` | 5 | 30 |
| `/28` | `255.255.255.240` | 4 | 14 |
| `/30` | `255.255.255.252` | 2 | 2 |
Each extra prefix bit halves the number of addresses. The "− 2" is there because two addresses in every network are reserved, as you'll see in [How it works](#how-it-works). Dividing a block into smaller networks is **subnetting**, covered in [06 — Subnetting](../06-subnetting/README.md).
> [!NOTE]
> **History: classful addressing.** Before 1993, the first bits of an address fixed its size: Class A (`0–127` in the first octet, a `/8`), Class B (`128–191`, a `/16`) and Class C (`192–223`, a `/24`), plus Class D (`224–239`, multicast) and Class E (`240–255`, reserved). This **classful addressing** wasted huge amounts of space, so CIDR replaced it (RFC 1519 in 1993, now RFC 4632). Today any prefix length is valid for any address. You'll still hear "a Class C" used loosely to mean "a `/24`".
> [!CHECK]
> Which subnet mask matches a `/20` prefix?
>
> - [ ] `255.255.255.240`
> - [x] `255.255.240.0`
> - [ ] `255.240.0.0`
> - [ ] `255.255.0.0`
>
> Twenty ones are 8 + 8 + 4: `255.255`, then `11110000` (240) in the third octet, then `0`. `255.255.255.240` is a `/28`, and `255.240.0.0` is a `/12`.
### Special-purpose addresses and delivery types
An IPv4 packet can be delivered in three ways:
- **Unicast:** to one interface. Almost all traffic is unicast.
- **Broadcast:** to every host on the local network. The **limited broadcast** address `255.255.255.255` (RFC 919) never leaves the local link. The **directed broadcast** address of a network (all host bits set to 1, for example `192.0.2.191` for `192.0.2.128/26`) targets every host on that specific network; routers don't forward it by default (RFC 2644, Best Current Practice BCP 34).
- **Multicast:** to every host that has joined a group, in `224.0.0.0/4` (RFC 5771). For example, `224.0.0.251` is used by multicast Domain Name System (mDNS, RFC 6762) on the local link.
Not every address can be used for every purpose. The Internet Assigned Numbers Authority (IANA) keeps the **IPv4 Special-Purpose Address Registry** (RFC 6890). Any address outside these blocks (and allocated to someone) is a **public address**: globally unique and routable on the Internet.
| Block | Range | Purpose | Reference |
|---|---|---|---|
| `0.0.0.0/8` | `0.0.0.0`–`0.255.255.255` | "This network". `0.0.0.0` means "no address yet" as a source, or "any address" when a service listens | RFC 791, RFC 1122 |
| `10.0.0.0/8` | `10.0.0.0`–`10.255.255.255` | Private | RFC 1918 |
| `100.64.0.0/10` | `100.64.0.0`–`100.127.255.255` | Shared address space for Carrier-Grade NAT (CGN) | RFC 6598 |
| `127.0.0.0/8` | `127.0.0.0`–`127.255.255.255` | Loopback: traffic never leaves the host (`127.0.0.1` = "this machine") | RFC 1122 |
| `169.254.0.0/16` | `169.254.0.0`–`169.254.255.255` | Link-local: self-assigned when no address is configured; not routed | RFC 3927 |
| `172.16.0.0/12` | `172.16.0.0`–`172.31.255.255` | Private | RFC 1918 |
| `192.0.2.0/24` | `192.0.2.0`–`192.0.2.255` | Documentation (TEST-NET-1) | RFC 5737 |
| `192.168.0.0/16` | `192.168.0.0`–`192.168.255.255` | Private | RFC 1918 |
| `198.51.100.0/24` | `198.51.100.0`–`198.51.100.255` | Documentation (TEST-NET-2) | RFC 5737 |
| `203.0.113.0/24` | `203.0.113.0`–`203.0.113.255` | Documentation (TEST-NET-3) | RFC 5737 |
| `224.0.0.0/4` | `224.0.0.0`–`239.255.255.255` | Multicast | RFC 5771 |
| `240.0.0.0/4` | `240.0.0.0`–`255.255.255.254` | Reserved (former Class E) | RFC 1112 |
| `255.255.255.255/32` | — | Limited broadcast | RFC 919 |
A few groups stand out:
- **Private addresses** (RFC 1918) can be used by anyone inside their own network, without asking anyone. They are not routed on the Internet, so millions of networks reuse them. That's why your VPNs clashed in the opening scenario.
- **Shared address space** `100.64.0.0/10` (RFC 6598) is for Internet service providers (ISPs) that run **Carrier-Grade NAT (CGN)**: one more layer of address translation inside the ISP. If your home router's outside (wide area network, WAN) address starts with `100.64`–`100.127`, you are behind CGN. Don't use this block for your own internal networks.
- **Documentation addresses** (RFC 5737) exist for books, slides and examples like this lesson. They are never assigned to real hosts.
> [!NOTE]
> The registry contains a few more blocks (for example `192.0.0.0/24` for Internet Engineering Task Force (IETF) protocol assignments and `198.18.0.0/15` for network benchmarking, RFC 2544) and records for each block whether it is globally reachable. Multicast has its own IANA registry (RFC 5771); it's in the table above because you meet it every day. Check the [IANA registry](https://www.iana.org/assignments/iana-ipv4-special-registry/) when you meet an address you don't recognize.
> [!CHECK]
> Which of these addresses is a private (RFC 1918) address?
>
> - [ ] `172.32.0.10`
> - [ ] `100.64.0.10`
> - [x] `172.31.200.10`
> - [ ] `192.0.2.10`
>
> The RFC 1918 block `172.16.0.0/12` runs from `172.16.0.0` to `172.31.255.255`, so `172.32.0.10` is outside it. `100.64.0.10` is CGN shared space and `192.0.2.10` is documentation space: both are special, but neither is RFC 1918.
### How a host gets an address
A host can get its IPv4 configuration in two ways:
| | Static addressing | DHCP |
|---|---|---|
| Who sets it | An administrator, by hand or with automation | A DHCP server, automatically |
| Typical use | Routers, servers, printers, network infrastructure | Laptops, phones, desktops, virtual machines |
| Strengths | Predictable; doesn't depend on a server | No typing errors; central control; addresses are reused |
| Weaknesses | Doesn't scale; easy to create duplicates | Depends on the DHCP server being reachable |
With **static addressing** you configure four values yourself: address, prefix length (or mask), **default gateway** (the router for everything off the local network) and Domain Name System (DNS) servers. The **Dynamic Host Configuration Protocol (DHCP)** (RFC 2131) hands out the same values automatically. DHCP runs over the User Datagram Protocol (UDP), with clients on port 68 and servers on port 67. Getting an address takes four messages, often remembered as **DORA**:
<figure class="diagram" style="--dg-w: 940px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 940 410" width="940" height="410" role="img" aria-labelledby="ip-dhcp-dora-title ip-dhcp-dora-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ip-dhcp-dora-title">DHCP: Discover, Offer, Request, Acknowledge</title>
<desc id="ip-dhcp-dora-desc">The client, with no address yet, broadcasts DISCOVER from 0.0.0.0 to 255.255.255.255. The DHCP server at 192.168.1.1 replies with an OFFER of 192.168.1.23/24 plus gateway, DNS and lease time. The client broadcasts a REQUEST for that address, and the server confirms with an ACK, which starts the lease.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="939" height="409" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<path class="dg-line" d="M190 98V394" stroke="#cfcfc8" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/>
<path class="dg-line" d="M750 98V394" stroke="#cfcfc8" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/>
<rect class="dg-card" x="85" y="24" width="210" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(99 38) scale(1.1667)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="137" y="56" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Client</text>
<text x="137" y="76" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500">no address yet</text>
<rect class="dg-card" x="645" y="24" width="210" height="74" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(659 38) scale(1.1667)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="697" y="56" font-size="14" class="dg-text" fill="#17171c" font-weight="700">DHCP server</text>
<text x="697" y="76" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.1</text>
<text x="470" y="128" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">DISCOVER</text>
<text x="470" y="145" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle">from 0.0.0.0 to 255.255.255.255 (broadcast)</text>
<g class="dg-l1"><circle class="dg-solid" cx="422" cy="124" r="11" fill="#0369a1"/><text x="422" y="128.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">D</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M194 159H744" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M736 153l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<text x="470" y="197" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">OFFER</text>
<text x="470" y="214" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle">192.168.1.23/24 · gateway · DNS · lease time</text>
<g class="dg-l7"><circle class="dg-solid" cx="433.25" cy="193" r="11" fill="#6d28d9"/><text x="433.25" y="197.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">O</text></g>
<g class="dg-l7"><path class="dg-stroke" d="M746 228H196" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><path class="dg-stroke" d="M204 222l-8 6 8 6" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<text x="470" y="266" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">REQUEST</text>
<text x="470" y="283" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle">"I'll take 192.168.1.23" (broadcast)</text>
<g class="dg-l1"><circle class="dg-solid" cx="425.75" cy="262" r="11" fill="#0369a1"/><text x="425.75" y="266.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">R</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M194 297H744" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M736 291l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<text x="470" y="335" font-size="12.5" class="dg-text" fill="#17171c" font-weight="600" text-anchor="middle">ACK</text>
<text x="470" y="352" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" text-anchor="middle">confirmed: the lease starts</text>
<g class="dg-l7"><circle class="dg-solid" cx="440.75" cy="331" r="11" fill="#6d28d9"/><text x="440.75" y="335.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">A</text></g>
<g class="dg-l7"><path class="dg-stroke" d="M746 366H196" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><path class="dg-stroke" d="M204 360l-8 6 8 6" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
</svg></figure>
*Figure 3. DHCP's four-message exchange. The client has no address yet, so it starts with a broadcast.*
The address is a **lease**, not a gift. By default the client tries to renew it with the same server halfway through the lease time. Because DISCOVER is a broadcast, it doesn't cross routers. On networks without a local DHCP server, the router runs a **DHCP relay agent** that forwards the request to a central server.
If no DHCP server answers, many operating systems give themselves a link-local address in `169.254.0.0/16` (RFC 3927; Windows calls this Automatic Private IP Addressing, APIPA). The host can then talk to neighbours on the same link but has no gateway, so it can't reach the Internet. That is the "no internet" server from the opening scenario.
**Why private addressing and NAT exist.** There aren't enough IPv4 addresses for every device: IANA handed out its last free blocks to the regional registries in 2011. The answer was to give internal devices private addresses and translate them at the edge. **Network Address Translation (NAT)** (RFC 3022) rewrites the source address of outgoing packets to the router's public address. The most common form, **Port Address Translation (PAT)** (also called NAPT or "NAT overload"), also rewrites the source port, so a whole network can share one public address:
<figure class="diagram" style="--dg-w: 940px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 940 330" width="940" height="330" role="img" aria-labelledby="ip-pat-title ip-pat-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="ip-pat-title">PAT: many private devices share one public address</title>
<desc id="ip-pat-desc">A laptop at 192.168.1.23 port 50514 and a phone at 192.168.1.40 port 50514 send traffic through the home router, whose inside address is 192.168.1.1 and outside address 203.0.113.7. The router's translation table maps the laptop to 203.0.113.7 port 61001 and the phone to 203.0.113.7 port 61002, so both share one public address on the Internet.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="939" height="329" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l2"><rect class="dg-tint" x="20" y="20" width="300" height="290" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 33) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></g>
<text x="62" y="47" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Private network</text></g>
<rect class="dg-card" x="44" y="64" width="252" height="96" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(60 80) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="102" y="101" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Laptop</text>
<text x="62" y="132" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.23:50514</text>
<rect class="dg-card" x="44" y="190" width="252" height="96" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(60 206) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2"/><path d="M12 18h.01"/></g>
<text x="102" y="227" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Phone</text>
<text x="62" y="258" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.40:50514</text>
<rect class="dg-card" x="360" y="40" width="400" height="250" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(376 54) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="8" x="2" y="14" rx="2"/><path d="M6.01 18H6"/><path d="M10.01 18H10"/><path d="M15 10v4"/><path d="M17.84 7.17a4 4 0 0 0-5.66 0"/><path d="M20.66 4.34a8 8 0 0 0-11.31 0"/></g>
<text x="418" y="76" font-size="15" class="dg-text" fill="#17171c" font-weight="700">Home router · PAT</text>
<text x="378" y="108" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">inside 192.168.1.1</text>
<text x="742" y="108" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">outside 203.0.113.7</text>
<text x="378" y="140" font-size="13" class="dg-text" fill="#17171c" font-weight="700">Translation table</text>
<g class="dg-l4"><rect class="dg-tint" x="376" y="152" width="368" height="122" rx="8" fill="#fbf2ee" stroke="#e7b39e"/></g>
<text x="390" y="176" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600">Inside address:port</text>
<text x="730" y="176" font-size="11.5" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="end">Outside address:port</text>
<text x="390" y="210" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.23:50514</text>
<text x="560" y="210" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle">→</text>
<g class="dg-l4"><text x="730" y="210" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="end" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7:61001</text></g>
<text x="390" y="248" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192.168.1.40:50514</text>
<text x="560" y="248" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle">→</text>
<g class="dg-l4"><text x="730" y="248" font-size="13" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="end" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.7:61002</text></g>
<path class="dg-line" d="M296 112H330V150H356" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M349 144l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M296 238H330V180H356" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M349 174l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M760 165H836" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<path class="dg-line" d="M829 159l8 6-8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<circle class="dg-card" cx="880" cy="165" r="38" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(863 148) scale(1.4167)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="880" y="226" font-size="14" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle">Internet</text>
</svg></figure>
*Figure 4. PAT: both devices share the public address `203.0.113.7`. The router remembers which outside port belongs to which inside address and port, and translates replies back.*
> [!CHECK]
> A laptop shows the address `169.254.37.12/16` and no default gateway. What is the most likely cause?
>
> - [ ] The ISP has put the laptop behind Carrier-Grade NAT
> - [x] The laptop didn't get an answer from a DHCP server and assigned itself a link-local address
> - [ ] An administrator configured a static address in a private range
> - [ ] The laptop is using the loopback interface
>
> `169.254.0.0/16` is the link-local block (RFC 3927) that hosts pick when DHCP fails. CGN uses `100.64.0.0/10`, and loopback is `127.0.0.0/8`. Check the cable, Wi-Fi association or DHCP server.
### A first look at IPv6
NAT kept IPv4 going, but it breaks the idea that any host can reach any other, and CGN adds cost and complexity for ISPs. **Internet Protocol version 6 (IPv6)** (RFC 8200) fixes the shortage at the source: its addresses are 128 bits long, so there are 2¹²⁸ (about 3.4 × 10³⁸) of them.
You recognize an IPv6 address by its colons and hexadecimal digits: eight groups of 16 bits, each written as up to four hex digits.
```text
Full form: 2001:0db8:0000:0010:0000:0000:0000:0082/64
Compressed form: 2001:db8:0:10::82/64
Network prefix: 2001:db8:0:10 (first 64 bits = first four groups)
Interface ID: ::82 (last 64 bits = 0:0:0:82)
```
- Leading zeros in a group can be dropped (`0db8` → `db8`), and one run of all-zero groups can be replaced by `::`. The exact rules (RFC 5952) are in module 07.
- The prefix length works exactly as in IPv4. A `/64` is the standard size for one network segment (a local area network, LAN), leaving 64 bits for the interface identifier.
- `2001:db8::/32` is the IPv6 documentation prefix (RFC 3849), the counterpart of RFC 5737. Addresses starting with `fe80:` are link-local, the counterpart of `169.254.0.0/16`.
Most networks today run IPv4 and IPv6 side by side (dual stack). Address types, autoconfiguration and planning are covered in [07 — IPv6](../07-ipv6/README.md).
> [!CHECK]
> In `2001:db8:0:10::82/64`, which part is the network prefix?
>
> - [ ] `2001:db8`, the first two groups
> - [x] `2001:db8:0:10`, the first four groups (64 bits)
> - [ ] `::82`, the last part after the double colon
> - [ ] The whole address, because IPv6 has no host part
>
> Each group is 16 bits, so a `/64` covers the first four groups. The `::` stands for the three all-zero groups between `10` and `82`, which belong to the interface identifier.
## How it works
Given any IPv4 address and prefix, you can work out its network by hand. Take `192.0.2.130/26` from Figure 2.
1. **Write the address in binary.** `192.0.2.130` → `11000000.00000000.00000010.10000010`.
2. **Write the mask.** `/26` → 26 ones, 6 zeros → `11111111.11111111.11111111.11000000` = `255.255.255.192`.
3. **Find the network address.** Keep the network bits and set every host bit to 0 (a bitwise AND of address and mask). Only the last octet changes: `10000010` AND `11000000` = `10000000` = 128. Network address: **`192.0.2.128`**.
4. **Find the broadcast address.** Keep the network bits and set every host bit to 1: `10111111` = 128 + 63 = 191. Broadcast address: **`192.0.2.191`**.
5. **Find the usable host range.** Everything in between: first host **`192.0.2.129`**, last host **`192.0.2.190`**.
6. **Count the hosts.** 6 host bits give 2⁶ = 64 addresses. Minus the network and broadcast addresses: **62 usable hosts**.
```text
Address 192.0.2.130 11000000.00000000.00000010.10|000010
Mask /26 11111111.11111111.11111111.11|000000
Network 192.0.2.128 11000000.00000000.00000010.10|000000 host bits all 0
Broadcast 192.0.2.191 11000000.00000000.00000010.10|111111 host bits all 1
First host 192.0.2.129 11000000.00000000.00000010.10|000001
Last host 192.0.2.190 11000000.00000000.00000010.10|111110
```
> [!TIP]
> A shortcut for the "interesting" octet (the one where the mask is neither 255 nor 0): the **block size** is 256 minus the mask value. For `.192` it is 64, so networks start at 0, 64, 128 and 192. The address `.130` falls in the block that starts at 128, and that block ends at 128 + 64 − 1 = 191.
A host uses the same calculation every time it sends a packet. If the destination is inside its own network, it delivers the packet directly on the link. If not, it sends it to the default gateway. This is why a wrong mask causes such strange faults.
> [!CHECK]
> What is the broadcast address of the network that contains `198.51.100.200/27`?
>
> - [ ] `198.51.100.255`
> - [ ] `198.51.100.207`
> - [x] `198.51.100.223`
> - [ ] `198.51.100.224`
>
> A `/27` has a block size of 32: networks start at .192 and .224. `.200` is in the `.192` block, which ends at 192 + 32 − 1 = 223. `.255` would be correct only for a `/24`, and `.224` is the start of the next network.
## Worked example
You log in to a Linux server and a Windows laptop and read their configuration. All values are documentation or private addresses; the MAC addresses come from the documentation block in RFC 7042.
**Linux server (static configuration).** List the addresses of one interface:
```bash
ip addr show dev eth0
```
```text
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:00:5e:00:53:82 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.130/26 brd 192.0.2.191 scope global eth0
valid_lft forever preferred_lft forever
inet6 2001:db8:0:10::82/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::200:5eff:fe00:5382/64 scope link
valid_lft forever preferred_lft forever
```
Read it line by line:
- `link/ether 00:00:5e:00:53:82` is the MAC address (Layer 2). `brd ff:ff:ff:ff:ff:ff` is the Ethernet broadcast address.
- `inet 192.0.2.130/26` is the IPv4 address and prefix length. `brd 192.0.2.191` is the broadcast address you calculated in How it works.
- `scope global` means the address is usable beyond this host (loopback addresses show `scope host`).
- `valid_lft forever` means the address doesn't expire: it was set statically. A DHCP address shows the word `dynamic` and a lifetime in seconds.
- `inet6 2001:db8:0:10::82/64` is a global IPv6 address with a `/64` prefix. `inet6 fe80::…` is the IPv6 link-local address; every IPv6 interface has one.
Now the routing table:
```bash
ip route
```
```text
default via 192.0.2.129 dev eth0 proto static metric 100
192.0.2.128/26 dev eth0 proto kernel scope link src 192.0.2.130 metric 100
```
- The second line is the **connected route**: the kernel created it from the address and prefix. Anything in `192.0.2.128/26` is delivered directly on `eth0`.
- The first line is the default route: everything else goes to the gateway `192.0.2.129`. The gateway is inside `192.0.2.128/26`, as it must be, or the host couldn't reach it.
**Windows laptop (DHCP).** In a terminal:
```text
ipconfig /all
```
Abbreviated output:
```text
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . : example.com
Physical Address. . . . . . . . . : 00-00-5E-00-53-23
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::1c2b:3d4e:5f60:7a8b%12(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.1.23(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Lease Obtained. . . . . . . . . . : Wednesday, 4 November 2026 08:12:40
Lease Expires . . . . . . . . . . : Thursday, 5 November 2026 08:12:40
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 192.168.1.1
```
- `192.168.1.23` with mask `255.255.255.0` is `192.168.1.23/24`: a private (RFC 1918) address on network `192.168.1.0/24`, broadcast `192.168.1.255`, hosts `.1` to `.254`.
- `DHCP Enabled: Yes`, the lease times and `DHCP Server` show that the address came from DHCP, with a 24-hour lease. The home router is the gateway, the DHCP server and the DNS forwarder at once, which is typical.
- `Autoconfiguration Enabled: Yes` means that if DHCP fails, Windows falls back to a `169.254.x.x` address (APIPA).
- `%12` after the link-local IPv6 address is the zone index: the interface number, needed because every interface has addresses in `fe80::/10`.
To reach the Internet, this laptop's traffic leaves with the router's public address, thanks to PAT. Nothing outside the home ever sees `192.168.1.23`.
> [!NOTE]
> Field names, order and date format vary with the Windows version and display language. On macOS, `ifconfig en0` shows the mask in hexadecimal (`netmask 0xffffff00` = `255.255.255.0`), and `ipconfig getpacket en0` shows the DHCP lease. You'll use these commands in the lab.
## Common pitfalls
- **Using `0` or `255` as a host address without thinking.** In a `/24`, `.0` is the network and `.255` the broadcast. In other prefixes they move: in `192.0.2.128/26`, `.128` and `.191` are reserved, and `.255` belongs to a different network. Always calculate.
- **Assuming the last octet is always the host part.** That's only true for a `/24`. `172.20.13.77/20` is on network `172.20.0.0/20`, which runs up to `172.20.15.255`.
- **Putting the default gateway outside the host's network.** The host must reach the gateway directly on the link. With `192.0.2.130/26`, a gateway of `192.0.2.1` is unreachable.
- **Picking `192.168.0.0/24` or `192.168.1.0/24` for an office or cloud network.** Home routers use them, so every remote worker on a VPN will clash. Choose a less common block, such as a random `/24` inside `10.0.0.0/8`, and plan it (see [module 06](../06-subnetting/README.md)).
- **Using `100.64.0.0/10`, documentation ranges or "unused" public space internally.** Shared space can collide with your ISP's CGN; documentation ranges can confuse tools; someone else owns that public space.
- **Treating `169.254.x.x` as a configuration to fix by hand.** It's a symptom. Fix the DHCP path (cable, Wi-Fi, virtual LAN or VLAN, relay, server) instead of setting a link-local address statically.
- **Expecting the "− 2" rule everywhere.** `/31` point-to-point links (RFC 3021) and `/32` host routes are special cases, covered in module 06.
## Security considerations
- **Private is not secure.** An RFC 1918 address only means "not routed on the Internet." Anything that reaches your network (a VPN user, a compromised laptop, a misconfigured cloud peering) can reach those hosts. Protect them with firewalls and authentication like any other host.
- **NAT is not a firewall.** PAT happens to drop unsolicited inbound traffic because there is no translation entry for it, but port forwarding, Universal Plug and Play (UPnP) and IPv6 (which usually has no NAT) all bypass that side effect. Use an explicit stateful firewall policy for both IPv4 and IPv6.
- **Don't leak internal addressing.** Internal IP addresses in public DNS records, error pages, email headers or published diagrams help an attacker map your network. Keep internal names in internal DNS, and use documentation ranges in anything you publish.
- **Source addresses can be spoofed.** IP doesn't verify the source address, so attackers forge it in reflection and amplification attacks. Network operators apply **ingress filtering** (BCP 38 / RFC 2827 and BCP 84 / RFC 3704): drop packets arriving from a customer with a source address that doesn't belong to that customer, and drop packets from the Internet with private, loopback or documentation source addresses.
- **Keep directed broadcasts off.** Forwarding directed broadcasts allowed old amplification attacks ("smurf" attacks). Routers have disabled it by default since RFC 2644 (BCP 34); don't turn it back on.
- **Watch for rogue DHCP servers.** Any device on the link can answer a DHCP DISCOVER and hand out a malicious gateway or DNS server. Switch features such as DHCP snooping limit answers to trusted ports.
## Summary
- An IP address identifies an interface and its location (network + host). A MAC address identifies a card on one link and changes at every hop.
- An IPv4 address is 32 bits, written as four octets in dotted decimal. The prefix length (`/26`) or subnet mask (`255.255.255.192`) says where the network part ends. Classful A/B/C is history; CIDR made any prefix valid.
- Network address = host bits all 0; broadcast = host bits all 1; usable hosts = 2ʰ − 2.
- Special-purpose blocks (RFC 6890) include private (RFC 1918), shared CGN space (RFC 6598), loopback, link-local, documentation (RFC 5737), multicast and limited broadcast.
- Hosts get addresses statically or from DHCP (DORA, leases). Private addressing plus NAT/PAT stretched IPv4; IPv6 (128 bits, `/64` per segment) is the long-term answer.
## Glossary
| Term | Definition |
|---|---|
| Internet Protocol (IP) address | A Layer 3 address that identifies a network interface and the network it belongs to. |
| Media Access Control (MAC) address | A 48-bit Layer 2 identifier used to deliver frames on the local link. |
| IPv4 address | A 32-bit IP address, written in dotted-decimal notation (RFC 791). |
| Dotted-decimal notation | Writing an IPv4 address as four decimal numbers (0–255) separated by dots. |
| Octet | A group of 8 bits; an IPv4 address has four. |
| Network part | The leading bits of an address, shared by all hosts on the same network. |
| Host part | The remaining bits, which identify one interface on that network. |
| Prefix length | The number of leading network bits, written after a slash (`/26`). |
| Classless Inter-Domain Routing (CIDR) | The addressing scheme in which any prefix length is valid; replaced classful addressing (RFC 4632). |
| Subnet mask | The prefix length written as a 32-bit dotted-decimal value with 1s for network bits (`255.255.255.192`). |
| Classful addressing | The obsolete scheme in which the first bits of an address fixed its network size (Classes A, B, C). |
| Subnetting | Dividing an address block into smaller networks (module 06). |
| Network address | The first address of a network: all host bits 0. Identifies the network itself. |
| Broadcast address | The last address of a network: all host bits 1. Reaches every host on that network. |
| Unicast | Delivery to a single interface. |
| Limited broadcast | `255.255.255.255`: every host on the local link; never forwarded by routers. |
| Directed broadcast | The broadcast address of a specific network (for example `192.0.2.191` for `192.0.2.128/26`). |
| Multicast | Delivery to every host that has joined a group; IPv4 range `224.0.0.0/4`. |
| IPv4 Special-Purpose Address Registry | IANA's list of reserved IPv4 blocks and their properties (RFC 6890). |
| Public address | A globally unique address that is routable on the Internet. |
| Private address | An address from the RFC 1918 blocks, usable by anyone internally and not routed on the Internet. |
| Shared address space | `100.64.0.0/10` (RFC 6598), reserved for ISPs' Carrier-Grade NAT. |
| Carrier-Grade NAT (CGN) | Address translation run by an ISP, so many customers share public addresses. |
| Documentation addresses | Blocks reserved for examples: `192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24` (RFC 5737). |
| Static addressing | Configuring a host's address, prefix, gateway and DNS by hand. |
| Default gateway | The router a host sends traffic to when the destination is outside its own network. |
| Dynamic Host Configuration Protocol (DHCP) | A protocol that assigns IP configuration to hosts automatically (RFC 2131). |
| DORA | Mnemonic for DHCP's four messages: Discover, Offer, Request, Acknowledge. |
| Lease | The period during which a DHCP-assigned address belongs to a client; it must be renewed. |
| DHCP relay agent | A router function that forwards DHCP broadcasts to a DHCP server on another network. |
| Network Address Translation (NAT) | Rewriting IP addresses in packet headers as they cross a router (RFC 3022). |
| Port Address Translation (PAT) | NAT that also rewrites ports so many hosts can share one public address; also called NAPT or NAT overload. |
| Internet Protocol version 6 (IPv6) | The successor to IPv4, with 128-bit addresses (RFC 8200). |
| Block size | The number of addresses in one network, counted in the octet where the mask is neither 255 nor 0 (256 minus the mask value). |
| Connected route | A route the operating system creates automatically for the network of a configured address. |
| Ingress filtering | Dropping packets whose source address can't legitimately come from where they arrived (BCP 38). |
## Check your understanding
1. Why can't routers on the Internet forward packets using MAC addresses instead of IP addresses?
2. Two hosts, `192.0.2.100/26` and `192.0.2.130/26`, are plugged into the same switch. Can they talk to each other directly? What would they need?
3. Your home router's WAN address is `100.72.14.9`. What does that tell you, and what might stop working?
4. A colleague proposes `192.168.1.0/24` for a new cloud network. What would you suggest instead, and why?
5. Why does a DHCP client start with a broadcast, and what does that mean for networks without their own DHCP server?
6. NAT hides internal addresses. Why is that still not a substitute for a firewall?
## References
- [RFC 791](https://www.rfc-editor.org/rfc/rfc791) — Internet Protocol (IPv4).
- [RFC 1122](https://www.rfc-editor.org/rfc/rfc1122) — Requirements for Internet Hosts — Communication Layers.
- [RFC 4632](https://www.rfc-editor.org/rfc/rfc4632) — Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan.
- [RFC 1918](https://www.rfc-editor.org/rfc/rfc1918) — Address Allocation for Private Internets.
- [RFC 6598](https://www.rfc-editor.org/rfc/rfc6598) — IANA-Reserved IPv4 Prefix for Shared Address Space.
- [RFC 5737](https://www.rfc-editor.org/rfc/rfc5737) — IPv4 Address Blocks Reserved for Documentation.
- [RFC 6890](https://www.rfc-editor.org/rfc/rfc6890) — Special-Purpose IP Address Registries.
- [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/).
- [RFC 3927](https://www.rfc-editor.org/rfc/rfc3927) — Dynamic Configuration of IPv4 Link-Local Addresses.
- [RFC 919](https://www.rfc-editor.org/rfc/rfc919) — Broadcasting Internet Datagrams.
- [RFC 2644](https://www.rfc-editor.org/rfc/rfc2644) — Changing the Default for Directed Broadcasts in Routers (BCP 34).
- [RFC 5771](https://www.rfc-editor.org/rfc/rfc5771) — IANA Guidelines for IPv4 Multicast Address Assignments.
- [RFC 2131](https://www.rfc-editor.org/rfc/rfc2131) — Dynamic Host Configuration Protocol.
- [RFC 3022](https://www.rfc-editor.org/rfc/rfc3022) — Traditional IP Network Address Translator (Traditional NAT).
- [RFC 8200](https://www.rfc-editor.org/rfc/rfc8200) — Internet Protocol, Version 6 (IPv6) Specification.
- [RFC 3849](https://www.rfc-editor.org/rfc/rfc3849) — IPv6 Address Prefix Reserved for Documentation.
- [RFC 2827](https://www.rfc-editor.org/rfc/rfc2827) — Network Ingress Filtering (BCP 38).
- [RFC 3704](https://www.rfc-editor.org/rfc/rfc3704) — Ingress Filtering for Multihomed Networks (BCP 84).
- [RFC 7042](https://www.rfc-editor.org/rfc/rfc7042) — IANA Considerations and IETF Protocol and Documentation Usage for IEEE 802 Parameters.