CloudAcademia
EN

Networking · Module 04 · The OSI Model: How Networks Talk

The OSI Model: How Networks Talk

Lesson45 minBeginnerMarkdown

Showing raw Markdown: the renderer could not load.

## Why this matters
It's Monday morning and users report that "the website is down." One colleague restarts the web server. Another reboots the office router. A third replaces a network cable. Nobody knows which fix worked, and the problem comes back on Tuesday.

The OSI model gives you a way to work through a problem like this in order. You ask questions one layer at a time: is the link up? Can you reach the server's Internet Protocol (IP) address? Is port 443 open? Does the application answer? Each question rules out a whole class of causes. Engineers, vendors and documentation use the same layer names ("that's a Layer 2 problem," "it's an L7 load balancer"), so learning the model also lets you follow those conversations.

## Learning objectives
- Explain why layered network models exist and what problems they solve.
- Identify the seven OSI layers in order, with each layer's main role and its protocol data unit (PDU).
- Map common protocols and devices to their layer (HTTP, TLS, TCP/UDP, IP, Ethernet, switch, router…).
- Describe encapsulation and decapsulation as data travels from sender to receiver.
- Compare the OSI model with the TCP/IP model.

## Key concepts

### Why layers?
Think about sending a parcel. You write a letter, put it in an envelope, and the postal service puts the envelope in a sack, the sack in a truck, and the truck on a road. You don't need to know the truck's route. The truck driver doesn't read your letter. Each party does one job and relies on the others to do theirs.

Networks work the same way. A **layered model** splits communication into stacked layers. Each layer:
- provides a **service** to the layer above it,
- uses the service of the layer below it,
- talks to the *same* layer on the other machine through a **protocol**.

This split brings three practical benefits:

| Benefit | What it means in practice |
|---|---|
| Modularity | You can swap Wi-Fi for Ethernet without changing your browser. |
| Interoperability | Hardware and software from different vendors work together because each follows the same layer contracts. |
| Troubleshooting | You can test one layer at a time and narrow a fault down quickly. |

> [!CHECK]
> Your office replaces its Wi-Fi with wired Ethernet. What do you need to change in your web browser?
>
> - [ ] Its proxy settings, because the link type changed
> - [x] Nothing: the browser uses the same service from the layers below
> - [ ] You need to reinstall it so it detects the new network card
>
> This is **modularity**. Changing a lower layer doesn't affect the layers above it, as long as each layer keeps providing the same service.

### The seven OSI layers
The **Open Systems Interconnection (OSI) model** is a reference model published by the International Organization for Standardization (ISO) as ISO/IEC 7498-1. It defines seven layers, numbered from the bottom up.

<figure class="diagram" style="--dg-w: 760px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 760 546" width="760" height="546" role="img" aria-labelledby="osi-seven-layers-title osi-seven-layers-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="osi-seven-layers-title">The seven layers of the OSI model</title>
<desc id="osi-seven-layers-desc">A stack of seven layers from top to bottom. 7 Application: network services for apps, PDU data. 6 Presentation: translates formats, encodes and encrypts, PDU data. 5 Session: opens, manages and closes dialogues, PDU data. 4 Transport: end-to-end delivery between processes using ports, PDU segment or datagram. 3 Network: addressing and routing across networks using IP, PDU packet. 2 Data Link: delivery to neighbours on one link using MAC addresses, PDU frame. 1 Physical: bits as electrical, light or radio signals, PDU bits. Upper layers are closer to the user, lower layers closer to the wire.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="759" height="545" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<text x="156" y="36" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700" letter-spacing="1.2">LAYER</text>
<text x="648" y="36" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" letter-spacing="1.2">PDU</text>
<path class="dg-line" d="M34 60V520" stroke="#cfcfc8" stroke-width="2" fill="none"/>
<path class="dg-line" d="M28 68l6-8 6 8M28 512l6 8 6-8" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<text x="0" y="0" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" transform="translate(22 161) rotate(-90)">Closer to the user</text>
<text x="0" y="0" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" transform="translate(22 419) rotate(-90)">Closer to the wire</text>
<g class="dg-l7">
<rect class="dg-tint" x="56" y="56" width="684" height="60" rx="12" fill="#f3eefc" stroke="#c5a9f0" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="86" r="16" fill="#6d28d9"/>
<text x="88" y="91" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">7</text>
<g class="dg-icon" transform="translate(116 73) scale(1.0833)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M2 9h20"/><path d="M6 6.5h.01"/><path d="M9 6.5h.01"/></g>
<text x="156" y="82" font-size="16" class="dg-ink" fill="#6d28d9" font-weight="700">Application</text>
<text x="156" y="102" font-size="13" class="dg-muted" fill="#5c5c68">Network services for apps: web, email, DNS</text>
<rect class="dg-solid" x="572" y="72" width="152" height="28" rx="14" fill="#6d28d9"/>
<text x="648" y="91" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Data</text>
</g>
<g class="dg-l6">
<rect class="dg-tint" x="56" y="124" width="684" height="60" rx="12" fill="#f8edf9" stroke="#daa4df" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="154" r="16" fill="#a21caf"/>
<text x="88" y="159" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">6</text>
<g class="dg-icon" transform="translate(116 141) scale(1.0833)" fill="none" stroke="#a21caf" stroke-width="1.8" 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="156" y="150" font-size="16" class="dg-ink" fill="#a21caf" font-weight="700">Presentation</text>
<text x="156" y="170" font-size="13" class="dg-muted" fill="#5c5c68">Translates formats; encodes and encrypts</text>
<rect class="dg-solid" x="572" y="140" width="152" height="28" rx="14" fill="#a21caf"/>
<text x="648" y="159" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Data</text>
</g>
<g class="dg-l5">
<rect class="dg-tint" x="56" y="192" width="684" height="60" rx="12" fill="#faedf2" stroke="#e5a3be" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="222" r="16" fill="#be185d"/>
<text x="88" y="227" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">5</text>
<g class="dg-icon" transform="translate(116 209) scale(1.0833)" fill="none" stroke="#be185d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3 4 7l4 4"/><path d="M4 7h16"/><path d="m16 21 4-4-4-4"/><path d="M20 17H4"/></g>
<text x="156" y="218" font-size="16" class="dg-ink" fill="#be185d" font-weight="700">Session</text>
<text x="156" y="238" font-size="13" class="dg-muted" fill="#5c5c68">Opens, manages and closes dialogues</text>
<rect class="dg-solid" x="572" y="208" width="152" height="28" rx="14" fill="#be185d"/>
<text x="648" y="227" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Data</text>
</g>
<g class="dg-l4">
<rect class="dg-tint" x="56" y="260" width="684" height="60" rx="12" fill="#faf0ec" stroke="#e7b39e" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="290" r="16" fill="#c2410c"/>
<text x="88" y="295" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text>
<g class="dg-icon" transform="translate(116 277) scale(1.0833)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"/><path d="M12 22V12"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="m7.5 4.27 9 5.15"/></g>
<text x="156" y="286" font-size="16" class="dg-ink" fill="#c2410c" font-weight="700">Transport</text>
<text x="156" y="306" font-size="13" class="dg-muted" fill="#5c5c68">End-to-end delivery between processes (ports)</text>
<rect class="dg-solid" x="572" y="276" width="152" height="28" rx="14" fill="#c2410c"/>
<text x="648" y="295" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Segment · Datagram</text>
</g>
<g class="dg-l3">
<rect class="dg-tint" x="56" y="328" width="684" height="60" rx="12" fill="#f9f1eb" stroke="#e1ba9d" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="358" r="16" fill="#b45309"/>
<text x="88" y="363" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text>
<g class="dg-icon" transform="translate(116 345) scale(1.0833)" fill="none" stroke="#b45309" 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="156" y="354" font-size="16" class="dg-ink" fill="#b45309" font-weight="700">Network</text>
<text x="156" y="374" font-size="13" class="dg-muted" fill="#5c5c68">Addressing and routing across networks (IP)</text>
<rect class="dg-solid" x="572" y="344" width="152" height="28" rx="14" fill="#b45309"/>
<text x="648" y="363" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Packet</text>
</g>
<g class="dg-l2">
<rect class="dg-tint" x="56" y="396" width="684" height="60" rx="12" fill="#ecf5ef" stroke="#a1ccb1" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="426" r="16" fill="#15803d"/>
<text x="88" y="431" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text>
<g class="dg-icon" transform="translate(116 413) scale(1.0833)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="16" y="16" width="6" height="6" rx="1"/><rect x="2" y="16" width="6" height="6" rx="1"/><rect x="9" y="2" width="6" height="6" rx="1"/><path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3"/><path d="M12 12V8"/></g>
<text x="156" y="422" font-size="16" class="dg-ink" fill="#15803d" font-weight="700">Data Link</text>
<text x="156" y="442" font-size="13" class="dg-muted" fill="#5c5c68">Delivery to neighbours on one link (MAC)</text>
<rect class="dg-solid" x="572" y="412" width="152" height="28" rx="14" fill="#15803d"/>
<text x="648" y="431" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Frame</text>
</g>
<g class="dg-l1">
<rect class="dg-tint" x="56" y="464" width="684" height="60" rx="12" fill="#ebf3f7" stroke="#9ac3d9" stroke-width="1.2"/>
<circle class="dg-solid" cx="88" cy="494" r="16" fill="#0369a1"/>
<text x="88" y="499" font-size="15" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text>
<g class="dg-icon" transform="translate(116 481) scale(1.0833)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"/></g>
<text x="156" y="490" font-size="16" class="dg-ink" fill="#0369a1" font-weight="700">Physical</text>
<text x="156" y="510" font-size="13" class="dg-muted" fill="#5c5c68">Bits as electrical, light or radio signals</text>
<rect class="dg-solid" x="572" y="480" width="152" height="28" rx="14" fill="#0369a1"/>
<text x="648" y="499" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600" text-anchor="middle">Bits</text>
</g>
</svg></figure>

*Figure 1. The seven OSI layers. Upper layers sit closer to the user; lower layers sit closer to the wire.*

| # | Layer | Main role | PDU | Addressing |
|---|---|---|---|---|
| 7 | Application | Gives applications access to network services (web, email, name resolution). | Data | Names, URLs |
| 6 | Presentation | Translates data formats: character encoding, compression, encryption. | Data | — |
| 5 | Session | Opens, coordinates and closes dialogues between applications. | Data | — |
| 4 | Transport | Delivers data between processes end to end; can add reliability, ordering and flow control. | Segment (Transmission Control Protocol, TCP) / datagram (User Datagram Protocol, UDP) | Ports |
| 3 | Network | Moves packets across multiple networks; chooses paths (routing). | Packet | IP addresses |
| 2 | Data Link | Moves frames between devices on the same link; detects transmission errors. | Frame | Media Access Control (MAC) addresses |
| 1 | Physical | Sends raw bits as electrical, optical or radio signals. | Bit | — |

A **protocol data unit (PDU)** is the block of data a layer works with: its own header (and sometimes trailer) plus the data from the layer above.

> [!TIP]
> A common mnemonic from Layer 1 up: **P**lease **D**o **N**ot **T**hrow **S**ausage **P**izza **A**way (Physical, Data Link, Network, Transport, Session, Presentation, Application).

> [!CHECK]
> Which layer works with **frames** and uses **MAC addresses**?
>
> - [ ] Layer 1, Physical
> - [x] Layer 2, Data Link
> - [ ] Layer 3, Network
> - [ ] Layer 4, Transport
>
> Layer 2 moves frames between devices on the same link and addresses them by MAC address. Layer 3 works with packets and IP addresses; Layer 4 with segments or datagrams and ports.

### Protocols and devices on each layer
Real protocols don't always fit neatly into one layer, but the usual mapping is:

| Layer | Example protocols and standards | Example devices |
|---|---|---|
| 7 Application | Hypertext Transfer Protocol (HTTP), Domain Name System (DNS), Simple Mail Transfer Protocol (SMTP), Secure Shell (SSH) | Layer 7 load balancer, web application firewall (WAF) |
| 6 Presentation | TLS (see note), character encodings (UTF-8), data formats (JPEG) | — |
| 5 Session | Remote procedure call (RPC) session handling, NetBIOS sessions | — |
| 4 Transport | TCP, UDP, QUIC (see note) | Layer 4 load balancer, stateful firewall |
| 3 Network | IPv4, IPv6, Internet Control Message Protocol (ICMP) | Router, Layer 3 switch |
| 2 Data Link | Ethernet (Institute of Electrical and Electronics Engineers, IEEE 802.3), Wi-Fi (IEEE 802.11) MAC, Address Resolution Protocol (ARP; see note) | Switch, wireless access point (bridging) |
| 1 Physical | Cabling and signalling standards (for example 1000BASE-T), radio | Hub, repeater, cable, transceiver |

> [!NOTE]
> Some protocols span layers and sources disagree on where they belong. **Transport Layer Security (TLS)** sits on top of TCP and provides encryption, so it is often placed at Layer 6, but some texts put it at Layer 4 or 5. **QUIC** runs over UDP and does transport work (reliability, streams) and includes TLS 1.3. **ARP** maps IP addresses (Layer 3) to MAC addresses (Layer 2) and is usually listed at Layer 2. The point is not to memorize one "right" answer. It is to understand what job the protocol does.

Most traffic today runs over TCP/IP, not over the original OSI protocols, so Layers 5 and 6 rarely appear as separate protocols. Applications usually handle those jobs themselves.

> [!CHECK]
> A router receives traffic for another network. Which information does it use to decide where to send it?
>
> - [ ] The destination MAC address
> - [x] The destination IP address
> - [ ] The destination TCP port
> - [ ] The URL in the HTTP request
>
> Routers are Layer 3 devices: they forward packets based on the destination IP address. MAC addresses only matter on the local link, and ports and URLs belong to higher layers that a plain router doesn't inspect.

### Encapsulation and decapsulation
**Encapsulation** is how each layer wraps the data from the layer above with its own header before passing it down. The receiver does the reverse: **decapsulation**. Each layer reads and removes its own header, then passes the rest up.

<figure class="diagram" style="--dg-w: 800px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 800 486" width="800" height="486" role="img" aria-labelledby="osi-encapsulation-title osi-encapsulation-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="osi-encapsulation-title">Encapsulation and decapsulation</title>
<desc id="osi-encapsulation-desc">Left, the sender: application data gets a TCP header and becomes a segment, then an IP header and becomes a packet, then an Ethernet header and a frame check sequence trailer and becomes a frame, then it is sent as bits. The bits travel over copper, fibre or radio. Right, the receiver does the reverse from the bottom up, removing one header at each layer.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="799" height="485" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-icon-neutral" transform="translate(22 24) 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="60" y="38" font-size="16" class="dg-text" fill="#17171c" font-weight="700">Sender</text>
<text x="60" y="57" font-size="12.5" class="dg-muted" fill="#5c5c68">Encapsulation: each layer adds its header</text>
<rect class="dg-panel" x="20" y="76" width="360" height="340" rx="12" fill="#f0f0ec"/>
<g class="dg-l7"><circle class="dg-solid" cx="46" cy="114" r="12" fill="#6d28d9"/><text x="46" y="118.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">7</text></g>
<text x="64" y="118.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Data</text>
<g class="dg-l7"><rect class="dg-tint" x="239" y="98" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="280.0" y="118.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M274 144l6 6 6-6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l4"><circle class="dg-solid" cx="46" cy="180" r="12" fill="#c2410c"/><text x="46" y="184.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text></g>
<text x="64" y="184.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Segment</text>
<g class="dg-l4"><rect class="dg-solid" x="199" y="164" width="38" height="32" rx="6" fill="#c2410c"/><text x="218.0" y="184.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="239" y="164" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="280.0" y="184.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M274 210l6 6 6-6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l3"><circle class="dg-solid" cx="46" cy="246" r="12" fill="#b45309"/><text x="46" y="250.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<text x="64" y="250.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Packet</text>
<g class="dg-l3"><rect class="dg-solid" x="163" y="230" width="34" height="32" rx="6" fill="#b45309"/><text x="180.0" y="250.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">IP</text></g>
<g class="dg-l4"><rect class="dg-solid" x="199" y="230" width="38" height="32" rx="6" fill="#c2410c"/><text x="218.0" y="250.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="239" y="230" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="280.0" y="250.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M274 276l6 6 6-6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l2"><circle class="dg-solid" cx="46" cy="312" r="12" fill="#15803d"/><text x="46" y="316.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<text x="64" y="316.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Frame</text>
<g class="dg-l2"><rect class="dg-solid" x="123" y="296" width="38" height="32" rx="6" fill="#15803d"/><text x="142.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Eth</text></g>
<g class="dg-l3"><rect class="dg-solid" x="163" y="296" width="34" height="32" rx="6" fill="#b45309"/><text x="180.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">IP</text></g>
<g class="dg-l4"><rect class="dg-solid" x="199" y="296" width="38" height="32" rx="6" fill="#c2410c"/><text x="218.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="239" y="296" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="280.0" y="316.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<g class="dg-l2"><rect class="dg-solid" x="323" y="296" width="38" height="32" rx="6" fill="#15803d"/><text x="342.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">FCS</text></g>
<path class="dg-line" d="M274 342l6 6 6-6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l1"><circle class="dg-solid" cx="46" cy="378" r="12" fill="#0369a1"/><text x="46" y="382.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<text x="64" y="382.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Bits</text>
<g class="dg-l1"><rect class="dg-tint" x="122" y="362" width="240" height="32" rx="6" fill="#ebf3f7" stroke="#9ac3d9"/><text x="242" y="382.5" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0100 1101 0110 1110 0101 …</text></g>
<g class="dg-icon-neutral" transform="translate(422 24) 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="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="460" y="38" font-size="16" class="dg-text" fill="#17171c" font-weight="700">Receiver</text>
<text x="460" y="57" font-size="12.5" class="dg-muted" fill="#5c5c68">Decapsulation: each layer reads and removes its header</text>
<rect class="dg-panel" x="420" y="76" width="360" height="340" rx="12" fill="#f0f0ec"/>
<g class="dg-l7"><circle class="dg-solid" cx="446" cy="114" r="12" fill="#6d28d9"/><text x="446" y="118.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">7</text></g>
<text x="464" y="118.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Data</text>
<g class="dg-l7"><rect class="dg-tint" x="639" y="98" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="680.0" y="118.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M674 150l6-6 6 6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l4"><circle class="dg-solid" cx="446" cy="180" r="12" fill="#c2410c"/><text x="446" y="184.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text></g>
<text x="464" y="184.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Segment</text>
<g class="dg-l4"><rect class="dg-solid" x="599" y="164" width="38" height="32" rx="6" fill="#c2410c"/><text x="618.0" y="184.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="639" y="164" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="680.0" y="184.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M674 216l6-6 6 6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l3"><circle class="dg-solid" cx="446" cy="246" r="12" fill="#b45309"/><text x="446" y="250.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text></g>
<text x="464" y="250.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Packet</text>
<g class="dg-l3"><rect class="dg-solid" x="563" y="230" width="34" height="32" rx="6" fill="#b45309"/><text x="580.0" y="250.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">IP</text></g>
<g class="dg-l4"><rect class="dg-solid" x="599" y="230" width="38" height="32" rx="6" fill="#c2410c"/><text x="618.0" y="250.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="639" y="230" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="680.0" y="250.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<path class="dg-line" d="M674 282l6-6 6 6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l2"><circle class="dg-solid" cx="446" cy="312" r="12" fill="#15803d"/><text x="446" y="316.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text></g>
<text x="464" y="316.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Frame</text>
<g class="dg-l2"><rect class="dg-solid" x="523" y="296" width="38" height="32" rx="6" fill="#15803d"/><text x="542.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">Eth</text></g>
<g class="dg-l3"><rect class="dg-solid" x="563" y="296" width="34" height="32" rx="6" fill="#b45309"/><text x="580.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">IP</text></g>
<g class="dg-l4"><rect class="dg-solid" x="599" y="296" width="38" height="32" rx="6" fill="#c2410c"/><text x="618.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">TCP</text></g>
<g class="dg-l7"><rect class="dg-tint" x="639" y="296" width="82" height="32" rx="6" fill="#f3eefc" stroke="#c5a9f0"/><text x="680.0" y="316.5" font-size="12" class="dg-ink" fill="#6d28d9" font-weight="700" text-anchor="middle">Data</text></g>
<g class="dg-l2"><rect class="dg-solid" x="723" y="296" width="38" height="32" rx="6" fill="#15803d"/><text x="742.0" y="316.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">FCS</text></g>
<path class="dg-line" d="M674 348l6-6 6 6" stroke="#cfcfc8" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<g class="dg-l1"><circle class="dg-solid" cx="446" cy="378" r="12" fill="#0369a1"/><text x="446" y="382.5" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">1</text></g>
<text x="464" y="382.5" font-size="13" class="dg-text" fill="#17171c" font-weight="600">Bits</text>
<g class="dg-l1"><rect class="dg-tint" x="522" y="362" width="240" height="32" rx="6" fill="#ebf3f7" stroke="#9ac3d9"/><text x="642" y="382.5" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="500" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0100 1101 0110 1110 0101 …</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M242 394V448H642V398" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linejoin="round"/><path class="dg-stroke" d="M635 405l7-8 7 8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/><rect class="dg-bg-plain" x="276" y="436" width="247" height="24" rx="12" fill="#ffffff"/><g class="dg-icon" transform="translate(286 439) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"/></g><text x="310" y="452.5" font-size="12.5" class="dg-ink" fill="#0369a1" font-weight="600">Medium: copper, fibre or radio</text></g>
</svg></figure>

*Figure 2. The sender wraps the data layer by layer; the receiver unwraps it in reverse. Eth = Ethernet header, FCS = frame check sequence (the Ethernet trailer used to detect transmission errors).*

Each layer only reads its own header. A switch looks at the Ethernet header. A router looks at the IP header. Only the destination host reads the TCP header and passes the data to the right application.

> [!CHECK]
> On the sender, which header is added **last**, just before the data is turned into signals?
>
> - [ ] The TCP header
> - [ ] The IP header
> - [x] The Ethernet header (and its FCS trailer)
> - [ ] The HTTP header
>
> Encapsulation goes from the top down: HTTP data, then the TCP header, then the IP header, then the Ethernet header and trailer at Layer 2. Layer 1 adds no header; it only sends the bits.

### OSI vs TCP/IP
The OSI model is a **reference model**: a vocabulary for describing networks. The Internet runs on the **TCP/IP model** (also called the Internet protocol suite), which RFC 1122 describes with four layers.

| OSI layers | TCP/IP layer (RFC 1122) | Examples |
|---|---|---|
| 7 Application, 6 Presentation, 5 Session | Application | HTTP, DNS, TLS, SSH |
| 4 Transport | Transport | TCP, UDP |
| 3 Network | Internet | IPv4, IPv6, ICMP |
| 2 Data Link, 1 Physical | Link | Ethernet, Wi-Fi |

Key differences:
- **Origin.** OSI was designed as a standard first, top down. TCP/IP grew out of protocols already running on early networks.
- **Granularity.** OSI separates session and presentation jobs. TCP/IP leaves them to the application.
- **Use today.** TCP/IP is what your devices actually run. OSI layer numbers are what people *say* ("Layer 2," "L7").

> [!NOTE]
> Some textbooks show a five-layer "hybrid" model that splits the TCP/IP Link layer into Data Link and Physical. That is a teaching convention. RFC 1122 itself defines four layers.

> [!CHECK]
> In the TCP/IP model described in RFC 1122, where do the jobs of the OSI Session and Presentation layers go?
>
> - [ ] Into the Transport layer
> - [x] Into the Application layer
> - [ ] Into the Internet layer
> - [ ] TCP/IP keeps them as two separate layers
>
> TCP/IP has four layers. OSI Layers 5, 6 and 7 all map to its Application layer, so applications (or libraries such as TLS) handle those jobs themselves.

## How it works
Follow one web request from a laptop to a web server on another network:

1. **Application (L7).** The browser builds an HTTP request: `GET / HTTP/1.1`, `Host: www.example.com`.
2. **Presentation (L6).** For HTTPS, TLS encrypts the request so only the server can read it.
3. **Session (L5).** The TLS session and the TCP connection keep the dialogue between browser and server together. There is no separate Layer 5 protocol here.
4. **Transport (L4).** TCP adds a header with the source port (a random high port) and destination port 443. The result is a segment.
5. **Network (L3).** IP adds a header with source and destination IP addresses. The result is a packet.
6. **Data Link (L2).** Ethernet adds a header with source and destination MAC addresses and a trailer with a frame check sequence (FCS). The destination MAC is the **default gateway** (the local router), not the web server, because the server is on another network.
7. **Physical (L1).** The network interface card sends the frame as signals on the cable or radio.
8. **Along the path.** Each router decapsulates up to Layer 3, reads the destination IP address, picks the next hop, and builds a **new** Layer 2 frame for the next link. The IP addresses stay the same end to end (unless network address translation, NAT, rewrites them). The MAC addresses change at every hop.
9. **At the server.** The server decapsulates up the stack: Ethernet, then IP, then TCP (port 443 identifies the web server process), then TLS decrypts, and the web server reads the HTTP request.

> [!CHECK]
> Your laptop sends a request to a web server on another network. What is the **destination MAC address** of the frame that leaves the laptop?
>
> - [ ] The web server's MAC address
> - [x] The default gateway's MAC address
> - [ ] The broadcast address `ff:ff:ff:ff:ff:ff`
> - [ ] The laptop's own MAC address
>
> MAC addresses only matter on the local link. The frame goes to the local router (default gateway), which builds a new frame for the next link. The destination IP address stays the server's address end to end.

## Worked example
Your laptop requests `https://www.example.com/`. In this example, the values are:

| Item | Value |
|---|---|
| Laptop IP address | `192.0.2.10` |
| Laptop MAC address | `00:00:5e:00:53:10` |
| Default gateway (router) MAC address | `00:00:5e:00:53:01` |
| `www.example.com` (resolved by DNS) | `203.0.113.80` |
| Source TCP port (ephemeral) | `50514` |
| Destination TCP port | `443` (HTTPS) |

> [!NOTE]
> These are documentation values: IP addresses from RFC 5737 and MAC addresses from the documentation block in RFC 7042. The real `www.example.com` resolves to different addresses.

The frame that leaves the laptop looks like this, from the outside in:

<figure class="diagram" style="--dg-w: 760px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 760 516" width="760" height="516" role="img" aria-labelledby="osi-frame-example-title osi-frame-example-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="osi-frame-example-title">The frame that leaves the laptop, from the outside in</title>
<desc id="osi-frame-example-desc">An Ethernet frame (layer 2) with destination MAC 00:00:5e:00:53:01 (the gateway), source MAC 00:00:5e:00:53:10 and EtherType 0x0800 for IPv4, ending with a 4-byte frame check sequence. Inside it, an IPv4 packet (layer 3) from 192.0.2.10 to 203.0.113.80, protocol 6 (TCP), TTL 64. Inside that, a TCP segment (layer 4) from port 50514 to port 443 (HTTPS). Inside that, an encrypted TLS record carrying the HTTP request GET / with Host www.example.com.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="759" height="515" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l2">
<rect class="dg-tint" x="20" y="20" width="720" height="476" rx="12" fill="#f1f7f3" stroke="#8ac09e" stroke-width="1.3"/>
<circle class="dg-solid" cx="46" cy="44" r="11" fill="#15803d"/>
<text x="46" y="48.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">2</text>
<text x="66" y="49" font-size="14.5" class="dg-ink" fill="#15803d" font-weight="700">Ethernet frame</text>
<text x="724" y="49" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">Layer 2 · Data Link</text>
</g>
<rect class="dg-card" x="36.0" y="64" width="222.7" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="48.0" y="82" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Destination MAC (gateway)</text>
<text x="48.0" y="101" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00:00:5e:00:53:01</text>
<rect class="dg-card" x="268.7" y="64" width="222.7" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="280.7" y="82" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Source MAC (laptop)</text>
<text x="280.7" y="101" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00:00:5e:00:53:10</text>
<rect class="dg-card" x="501.3" y="64" width="222.7" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="513.3" y="82" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">EtherType</text>
<text x="513.3" y="101" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0x0800 = IPv4</text>
<g class="dg-l2"><rect class="dg-solid" x="36" y="450" width="688" height="30" rx="8" fill="#15803d"/><text x="48" y="470" font-size="12.5" class="dg-on" fill="#ffffff" font-weight="600">FCS · frame check sequence (4-byte trailer)</text></g>
<g class="dg-l3">
<rect class="dg-tint" x="36" y="124" width="688" height="310" rx="12" fill="#faf5f0" stroke="#daa984" stroke-width="1.3"/>
<circle class="dg-solid" cx="62" cy="148" r="11" fill="#b45309"/>
<text x="62" y="152.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">3</text>
<text x="82" y="153" font-size="14.5" class="dg-ink" fill="#b45309" font-weight="700">IPv4 packet</text>
<text x="708" y="153" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">Layer 3 · Network</text>
</g>
<rect class="dg-card" x="52.0" y="168" width="156.5" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="64.0" y="186" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Source IP</text>
<text x="64.0" y="205" font-size="13" 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="218.5" y="168" width="156.5" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="230.5" y="186" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Destination IP</text>
<text x="230.5" y="205" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">203.0.113.80</text>
<rect class="dg-card" x="385.0" y="168" width="156.5" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="397.0" y="186" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Protocol</text>
<text x="397.0" y="205" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">6 = TCP</text>
<rect class="dg-card" x="551.5" y="168" width="156.5" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="563.5" y="186" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">TTL</text>
<text x="563.5" y="205" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">64</text>
<g class="dg-l4">
<rect class="dg-tint" x="52" y="228" width="656" height="190" rx="12" fill="#fbf4f0" stroke="#e0a086" stroke-width="1.3"/>
<circle class="dg-solid" cx="78" cy="252" r="11" fill="#c2410c"/>
<text x="78" y="256.5" font-size="12" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle">4</text>
<text x="98" y="257" font-size="14.5" class="dg-ink" fill="#c2410c" font-weight="700">TCP segment</text>
<text x="692" y="257" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">Layer 4 · Transport</text>
</g>
<rect class="dg-card" x="68.0" y="272" width="201.3" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="80.0" y="290" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Source port (ephemeral)</text>
<text x="80.0" y="309" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">50514</text>
<rect class="dg-card" x="279.3" y="272" width="201.3" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="291.3" y="290" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Destination port</text>
<text x="291.3" y="309" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">443 = HTTPS</text>
<rect class="dg-card" x="490.7" y="272" width="201.3" height="48" rx="8" fill="#ffffff" stroke="#e3e3dd"/>
<text x="502.7" y="290" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="500">Control</text>
<text x="502.7" y="309" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">seq · ack · flags</text>
<g class="dg-l6"><rect class="dg-tint" x="68" y="332" width="624" height="70" rx="12" fill="#f9f1fa" stroke="#d08ed7" stroke-width="1.3" stroke-dasharray="5 4"/><g class="dg-icon" transform="translate(82 345) scale(0.9167)" fill="none" stroke="#a21caf" stroke-width="1.8" 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="114" y="361" font-size="14.5" class="dg-ink" fill="#a21caf" font-weight="700">TLS record · encrypted</text><text x="676" y="361" font-size="12" class="dg-muted" fill="#5c5c68" font-weight="500" text-anchor="end">Layers 5–7</text><text x="114" y="385" font-size="13" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">GET / HTTP/1.1 · Host: www.example.com</text></g>
</svg></figure>

*Figure 3. The frame from the worked example, from the outside in. Each box is the payload of the box around it.*

What each field tells the receiver:
- **EtherType `0x0800`** tells the receiver that the payload is IPv4 (IPv6 uses `0x86DD`).
- **Protocol `6`** in the IP header says the payload is TCP (UDP is `17`).
- **Destination port `443`** tells the server's operating system which process gets the data.
- **TTL 64** is a common starting value; each router decrements it by one. Initial values vary by operating system.

Count the overhead on a standard Ethernet link with a maximum transmission unit (MTU) of 1500 bytes:

| Header | Minimum size |
|---|---|
| Ethernet header + FCS | 14 + 4 = 18 bytes (not counted in the MTU) |
| IPv4 header | 20 bytes |
| TCP header | 20 bytes |
| Room left for application data | 1500 − 20 − 20 = **1460 bytes** |

That 1460-byte figure is the typical TCP maximum segment size (MSS) on Ethernet. You'll see it again in the lab capture.

After the first router, the frame looks different: the router's own MAC address is the source and the next hop's MAC address is the destination. The IP header (except for TTL and checksum) and everything inside it stay the same.

## Common pitfalls
- **Saying "packet" for every PDU.** It is fine in casual talk, but in troubleshooting the word matters. A switch forwards *frames*. A router forwards *packets*.
- **Expecting the destination MAC address to be the remote server.** MAC addresses only matter on the local link. For a remote destination, the frame goes to the default gateway's MAC address.
- **Treating the model as a strict rulebook.** Real protocols (TLS, QUIC, ARP, Multiprotocol Label Switching or MPLS) blur layer boundaries. Use the model to reason, not to argue over labels.
- **Mixing up model numbering.** "Layer 3" always means the OSI Network layer, even when people are talking about TCP/IP networks. TCP/IP layers are usually named, not numbered.
- **Skipping the lower layers when troubleshooting.** A flapping cable (L1) can look like a slow application (L7). Check from the bottom up, or from the top down, but in order.

## Security considerations
Every layer has its own threats, so security controls need to exist at several layers. This approach is called **defense in depth**.

| Layer | Example threat | Example defenses |
|---|---|---|
| 7 Application | Injection, credential stuffing, abuse of application programming interfaces (APIs) | Input validation, WAF, strong authentication, rate limiting |
| 6 Presentation | Eavesdropping on unencrypted data, weak cipher suites | TLS 1.2+ (prefer TLS 1.3), certificate validation |
| 4 Transport | TCP SYN floods, port scanning | SYN cookies, stateful firewalls, closing unused ports |
| 3 Network | IP address spoofing, route hijacking | Ingress filtering (Best Current Practice BCP 38 / RFC 2827), access control lists, route filtering |
| 2 Data Link | ARP spoofing, MAC flooding, rogue access points | Dynamic ARP inspection, switch port security, 802.1X port authentication, Wi-Fi Protected Access 3 (WPA3) |
| 1 Physical | Cable tapping, unauthorized device plugged in, jamming | Physical access control, locked network closets, disabling unused ports |

Two takeaways:
- **Encryption at one layer only protects the layers above it.** TLS hides your HTTP request, but IP addresses, ports and the server name in the TLS handshake (unless Encrypted Client Hello is used) stay visible to anyone on the path.
- **A firewall's layer limits what it can see.** A Layer 4 firewall can block port 23 but can't tell a malicious HTTP request from a normal one. That needs a Layer 7 control.

> [!IMPORTANT]
> Only capture or analyse traffic on networks and devices you own or are explicitly authorized to test. The lab in this module uses your own machine only.

## Summary
- Layered models split networking into independent jobs. That makes networks modular, interoperable and easier to troubleshoot.
- The OSI model has seven layers: Physical, Data Link, Network, Transport, Session, Presentation, Application. Each has a PDU: bits, frames, packets, segments/datagrams, data.
- Switches work mainly at Layer 2 (MAC addresses), routers at Layer 3 (IP addresses), TCP/UDP at Layer 4 (ports), HTTP and DNS at Layer 7.
- Sending data is encapsulation (each layer adds a header); receiving is decapsulation. MAC addresses change at every hop; IP addresses stay end to end unless NAT rewrites them.
- The Internet runs on the four-layer TCP/IP model. OSI remains the shared vocabulary.

## Glossary
| Term | Definition |
|---|---|
| Layered model | A way of describing communication as a stack of layers, each providing a service to the layer above and using the layer below. |
| Service | What a layer offers to the layer directly above it (for example, "deliver this packet to that IP address"). |
| Protocol | The rules two peers at the same layer follow to communicate (message format, order, meaning). |
| Open Systems Interconnection (OSI) model | ISO's seven-layer reference model for network communication (ISO/IEC 7498-1). |
| Protocol data unit (PDU) | The unit of data at a given layer: its header (and trailer, if any) plus the payload from the layer above. |
| Transport Layer Security (TLS) | A protocol that encrypts and authenticates data between two applications, most often on top of TCP. |
| QUIC | A transport protocol that runs over UDP, provides reliable multiplexed streams and integrates TLS 1.3 (RFC 9000). |
| Encapsulation | Adding a layer's header (and trailer) around the data received from the layer above. |
| Decapsulation | Reading and removing a layer's header at the receiver, then passing the payload up. |
| Reference model | A conceptual framework that describes functions, not a specific set of protocols you install. |
| TCP/IP model | The four-layer model of the Internet protocol suite (Link, Internet, Transport, Application) described in RFC 1122. |
| Default gateway | The router a host sends traffic to when the destination is outside its local network. |
| Defense in depth | Using several independent security controls, at different layers, so one failure doesn't expose everything. |

## Check your understanding
1. A colleague says "the switch dropped the packet." Which word would be more precise, and why does it matter?
2. Your laptop sends data to a server on another continent. Which addresses in the frame change at each router, and which stay the same?
3. Why does a TLS-encrypted connection still reveal the server's IP address and destination port to observers on the path?
4. A Layer 4 load balancer and a Layer 7 load balancer both sit in front of a website. What can the Layer 7 one decide that the Layer 4 one can't?
5. Which OSI layers does the TCP/IP Application layer cover, and why did TCP/IP not need separate layers for them?

## References
- ISO/IEC 7498-1:1994 — Information technology — Open Systems Interconnection — Basic Reference Model: The Basic Model (also published as ITU-T Recommendation X.200).
- [RFC 1122](https://www.rfc-editor.org/rfc/rfc1122) — Requirements for Internet Hosts — Communication Layers.
- [RFC 791](https://www.rfc-editor.org/rfc/rfc791) — Internet Protocol (IPv4).
- [RFC 9293](https://www.rfc-editor.org/rfc/rfc9293) — Transmission Control Protocol (TCP).
- [RFC 768](https://www.rfc-editor.org/rfc/rfc768) — User Datagram Protocol (UDP).
- [RFC 8446](https://www.rfc-editor.org/rfc/rfc8446) — The Transport Layer Security (TLS) Protocol Version 1.3.
- [RFC 9000](https://www.rfc-editor.org/rfc/rfc9000) — QUIC: A UDP-Based Multiplexed and Secure Transport.
- [RFC 2827](https://www.rfc-editor.org/rfc/rfc2827) — Network Ingress Filtering (BCP 38).
- [RFC 5737](https://www.rfc-editor.org/rfc/rfc5737) — IPv4 Address Blocks Reserved for Documentation.
- [RFC 7042](https://www.rfc-editor.org/rfc/rfc7042) — IANA Considerations and IETF Protocol and Documentation Usage for IEEE 802 Parameters.
- IEEE 802.3 — Ethernet.