COE 558Lecture 01Part 03
The Internet and the TCP/IP stack
Why connectivity is split into five layers, what each layer sends and addresses, and where each layer lives inside a computer.
- Concepts
- 5
- Slides
- 22-29
- Reading
- 30 min
Why this part matters
Every idea later in this lecture assumes you can say exactly what crosses the network: which header each hop reads, and which address identifies what. Latency budgets, sockets, containers and the mapping of tasks onto device, edge, fog and cloud all rest on this vocabulary.
This part turns the TCP/IP stack from a list to memorize into a working mental picture. We follow one real request from the lamp system in part 02 as it is wrapped, addressed, forwarded and delivered, and then we open up the computer to see where each step physically happens. The layer table and the address-per-scope table are classic exam questions, and the same vocabulary is what your research project uses to describe where sensing, processing and storage sit.
By the end you can
- Explain why connectivity is split into five layers, and name each layer with one protocol.
- Trace encapsulation from message to bits, stating each PDU and the payload it carries.
- Match the E2E, H2H and P2P scopes to port, IP and MAC addresses, and say which change per hop.
- Tell a socket, a connection and a flow apart, and write out the 5-tuple.
- Place each layer in application space, the OS kernel or the NIC, and name the seams between them.
In part 02 a browser controlled a lamp with HTTP requests: PUT /lamp/state to switch it and GET /lamp/energy to read its energy. Each request started on a laptop on KFUPM Wi-Fi and had to reach a server that might sit in a data center on another continent. Neither program knew the path in between, and neither needed to. That is the whole point of the TCP/IP stack.
Every host runs the same set of layers, so a client and a server can exchange bytes as if a private pipe joined them. The stack has a single purpose: connectivity. A program should only have to say who it wants to talk to and what it wants to send. Everything else in this part (layers, PDUs, addresses, sockets) is simply how that one job gets done.
Why split connectivity into layers
Hiding the path is a large job, far too large for one piece of software. Think about an air journey. You buy a ticket, check a bag, pass a gate, the plane takes off from a runway and air traffic control routes it. Each step relies on the step below it and offers a service to the step above. Kurose and Ross use exactly this example to motivate network layering.
The Internet divides connectivity the same way. The stack has five layers, and each layer provides one well-defined service using its own protocols. The payoff is explicit structure and modularity: a layer can change how it works internally without the rest of the system noticing. Wi-Fi can be swapped for 5G, and HTTP does not change a single byte.
Read the plus signs as composition, not arithmetic. No single layer delivers a web page. Connectivity emerges only when all five cooperate, the same way no single airport worker delivers you to another city.
| Layer | Abbreviation | One-line job | Example protocols |
|---|---|---|---|
| Application | AL | Supports network applications | HTTP, SMTP, IMAP |
| Transport | TL | Process-to-process data transfer | TCP, UDP |
| Network | NL | Routes datagrams from source host to destination host | IP, routing protocols |
| Data link | DLL | Moves data between neighboring network elements | Ethernet, 802.11, PPP |
| Physical | PL | Puts bits on the wire or into the air | Signal encodings of Ethernet and Wi-Fi |
Five layers versus seven
Part 02 used OSI as its example of a layered system, so it is worth lining the two models up. The OSI reference model (ITU-T X.200) defines seven layers. The Internet stack has no separate session or presentation layer. RFC 1122 says the Internet application layer essentially combines OSI presentation and application, and Kurose and Ross note that any such services must be implemented by the application itself.
| OSI layer | TCP/IP layer |
|---|---|
| 7 Application | Application |
| 6 Presentation | Folded into the application |
| 5 Session | Folded into the application |
| 4 Transport | Transport |
| 3 Network | Network |
| 2 Data link | Data link |
| 1 Physical | Physical |
Recall
Which two OSI layers have no separate layer in the TCP/IP stack, and where do their functions go?
The stack as the band between people and the physical world
Now zoom out to a whole system. Picture a distance sensor such as the HC-SR04 wired to a Raspberry Pi Pico. The Pico reads a distance, a Wi-Fi-capable board sends it across the network, and a dashboard in a control room shows it to a person. A command can travel the other way, down to an actuator.
The five layers form a band in the middle of that picture. Users sit above it and the physical world of sensing and actuation sits below it. The dashboard does not need to know how bits cross the air, and the device does not need to know how the dashboard draws its charts. This is modularity again, now at the scale of an entire system.
Read sensor values and send commands.
Five layers that give the two ends connectivity.
Measure the world and act on it.
This is the same shape as the lamp system from part 02, and it is also the shape of your research project. In parts 08 to 10 the same pipeline is stretched across the edge to cloud continuum, and the question becomes where along it each piece of processing should run.
Layers cooperate by handing data to each other, and the way they do it is the single most useful mechanism in this part. Take a simple read request, GET /lamp HTTP/1.1. The application layer hands it down as a message. Transport puts a TCP header in front and it becomes a segment. Network adds an IP header and it becomes a packet. Data link adds a MAC header in front and a frame check sequence (a CRC) trailer behind, making a frame. Physical sends that frame as bits.
Each layer's unit of data is its protocol data unit (PDU). The process of wrapping is encapsulation, and it follows one rule: a PDU is this layer's header plus a payload, and the payload is the entire PDU of the layer above. On the receiving host the steps run in reverse. Each layer reads and removes its own header, then passes the payload up. Step through it yourself before reading on.
- Layer
- Application
- PDU
- Message
- Address
- None: the app just writes data
- Adds
- The HTTP request itself
- Request
- GET /lamp HTTP/1.1
| Layer | PDU | Payload | Example protocols | Address |
|---|---|---|---|---|
| Application | Message | Application bytes | HTTP | None |
| Transport | Segment (TCP) or datagram (UDP) | Message | TCP, UDP | Port number |
| Network | Packet (also called datagram) | Segment or UDP datagram | IP | IP address |
| Data link | Frame | Packet | Ethernet, 802.11, PPP | MAC address |
| Physical | Bits | Frame, as signals | Physical specs of Ethernet and Wi-Fi | None |
Who reads which header
Encapsulation is also what lets the middle of the network stay simple. Kurose and Ross label the headers Ht (transport), Hn (network) and Hl (link). A switch processes only the link and physical layers. A router processes network, link and physical. Only the two end hosts open the transport header and the application message. The IP header even carries a Protocol field that names the next-level protocol in its data (RFC 791, section 3.1), which is how the receiver knows whether to hand the payload to TCP or UDP.
Minimum header sizes
- IPv4 header
- 20 bytes
- TCP header (no options)
- 20 bytes
- UDP header
- 8 bytes
These sizes come from RFC 791, RFC 9293 and RFC 768, and together they are the 40 bytes of layering overhead mentioned earlier. They also reveal a division of labor: IP has no acknowledgments, no retransmissions and no flow control (RFC 791, section 1.4). Reliability is added one layer up, by TCP, and only at the end hosts.
Quick check
In the TCP/IP stack, what does a network-layer packet carry as its payload?
Recall
What is the payload of a data-link frame, and what is the payload of that payload?
The header table ended with an address column, and that column is not decoration. Each header names something different because each layer connects something different. Your laptop on campus loads a page from a cloud server. The path goes over one Wi-Fi hop to the access point, through several routers, and finally over a data-center link to the server. Along that path there is one conversation between two programs, one route between two machines, and many separate links.
These are the three connection scopes. The transport layer provides an end-to-end (E2E) connection between two application processes. The network layer provides a host-to-host (H2H) path between two machines, however many routers lie between them. The data link layer handles point-to-point (P2P) transfer across a single hop between two directly attached interfaces.
| Scope | Between | Virtual or physical | Count along one path |
|---|---|---|---|
| E2E (transport) | Two application processes | Virtual | One |
| H2H (network) | Two hosts, across routers | Virtual | One |
| P2P (data link) | Two adjacent interfaces | Physical link | One per hop |
The rule to take away: the higher the layer, the wider its scope and the more virtual its connection. Only the P2P links are real cables or radio channels. The E2E connection is not a wire at all. It is state held in the two end hosts: RFC 9293 (section 3.3.1) describes the TCP control block that stores the local and remote IP addresses and ports. TCP creates that state with the three-way handshake (section 3.5), while IP itself is connectionless. UDP keeps no connection state at all, yet its datagrams are still delivered process to process.
Quick check
Which connection scope exists between two application processes rather than two machines?
Recall
How many E2E, H2H and P2P connections exist when your laptop reaches a server through four routers? (Treat the Wi-Fi access point as part of the first link.)
One address per scope
If each scope connects a different kind of thing, each needs its own way to name that thing. Look back at the encapsulation stepper. The server is 3.120.0.10, the service on it is port 443, and the next hop's interface is f4:8c:50:2b:e1:04. Three addresses, one per scope.
E2E names a process with a port number. H2H names a machine with an IP address. P2P names a network interface on the local link with a MAC address. (The course materials write "Mac"; the standard spelling is MAC, for Media Access Control.)
Address sizes
- Port number
- 16 bits, values 0 to 65535
- IPv4 address
- 32 bits (four octets)
- MAC address
- 48 bits (EUI-48, six octets)
Ports are 16-bit fields in both TCP (RFC 9293) and UDP (RFC 768). IPv4 addresses are a fixed four octets (RFC 791, section 2.3). MAC addresses are 48 bits, burned into the NIC but sometimes settable in software, written like 1A-2F-BB-76-09-AD.
| Range | Name | Example |
|---|---|---|
| 0 to 1023 | System ports | HTTPS on 443 |
| 1024 to 49151 | User ports | Registered application services |
| 49152 to 65535 | Dynamic ports | Client source port 51514 |
What changes at each hop
Putting scopes and addresses together gives the most useful insight of this concept. Along the whole path, ignoring NAT, the source and destination IP addresses and ports stay the same, because their scopes span the whole path. The MAC addresses are replaced at every hop, because their scope is one link: each router strips the old frame and builds a new one for the next link. To build it, the router uses ARP (RFC 826) to map the next hop's IP address to its 48-bit Ethernet address.
Quick check
A router forwards your packet toward a cloud server. Ignoring NAT, which address does it replace for the next hop?
Recall
Along a path from your laptop to a cloud server, which addresses stay the same and which change at every hop?
Addresses name endpoints, but a conversation needs more than one name. Open two browser tabs to the same server. Both tabs run on one laptop with one IP address, and both talk to one server port. Yet every reply lands in the right tab. Something must tell the two conversations apart.
Worked example
Two tabs, one server
Server socket
3.120.0.10:443Tab A socket
10.0.0.7:51514Tab B socket
10.0.0.7:51515Only the source port differs
Both flows are TCP from 10.0.0.7 to 3.120.0.10:443. Only the source ports 51514 and 51515 differ, so the OS delivers each reply to the right tab.
The general rule builds up in three steps. A socket is one endpoint, an IP address plus a port number. A connection is a pair of sockets, one at each end, which is exactly how RFC 9293 defines it. When networks need to tell flows apart, they add the protocol and use the 5-tuple, which RFC 6437 (section 3) lists as destination address, source address, protocol, destination port and source port. The protocol field is what separates a TCP flow from a UDP flow that happens to share the same addresses and ports.
Notice how this ties back to the scopes. The 5-tuple uses only the E2E and H2H addresses, the ones that survive the whole path. The MAC address plays no part in identifying a connection, because it covers only one hop and would change before the reply ever came back.
Quick check
Two browser tabs on one laptop connect to the same server on port 443. What lets the operating system tell the two connections apart?
Recall
What identifies a socket, and what identifies a flow?
So far the layers have been abstractions. The last step is to find them inside a real computer. A Node.js server asks the operating system for a socket and gets back a file descriptor. It writes bytes to that descriptor. Inside the kernel, TCP and IP headers are added. A driver hands the finished frame to the network card, which turns it into electrical or radio signals.
That story maps the layers onto three parts of one machine. The application layer lives in application space: the browser or server process, including its HTTP library. The transport layer and network layer live in the operating system kernel. The data link layer and physical layer live in the network interface and its driver.
Two seams separate these spaces. The socket API is the door between application and OS, which is why the socket of the previous concept is also a programming object. The Linux socket(7) manual calls sockets the uniform interface between the user process and the network protocol stacks in the kernel. Drivers are the door between OS and hardware. For the Web, the concrete stack reads: browser or server, HTTP, socket API, TCP, IP, Ethernet, then wired or wireless media.
| Space | Layers | Example |
|---|---|---|
| Application space | AL | Browser or Node.js server with its HTTP code |
| Operating system kernel | TL, NL | TCP and IP implementations, reached through sockets |
| Hardware (NIC and driver) | DLL, PL | Ethernet or Wi-Fi chip, firmware and driver |
The seams are also boundaries of privilege. An application cannot forge TCP state directly; it has to go through the socket API. This matters later in the course. Latency is added at every crossing, and virtual machines and containers in lecture 2 virtualize exactly these seams.
Quick check
On a laptop browsing the Web, where does the TCP implementation normally run?
Recall
Where do TCP and IP normally run in a computer, and what is the interface an application uses to reach them?
Recap
If you remember nothing else
- The TCP/IP stack exists to give a client and a server connectivity, and connectivity emerges from all five layers working together.
- OSI has seven layers, and TCP/IP folds session and presentation into the application.
- The PDUs are message, segment, packet (datagram), frame and bits, and each payload is the PDU of the layer above.
- Routers process only the network, link and physical layers. Only end hosts read transport headers and application messages.
- Transport connects processes end to end using 16-bit ports.
- Network connects hosts using 32-bit IPv4 addresses.
- Data link connects adjacent interfaces using 48-bit MAC addresses, which are rewritten at every hop.
- A socket is an IP address plus a port, a connection is a pair of sockets, and a flow is identified by the 5-tuple.
- Applications live in user space, TCP and IP in the kernel behind the socket API, and link and physical in the NIC and its driver.
Sources
- Computer Networking: A Top-Down Approach, 9th editionBookPearson (Kurose and Ross)Published June 2025(opens in a new tab)
- Kurose and Ross companion siteDocsUniversity of Massachusetts AmherstSlides, animations, Wireshark labs(opens in a new tab)
- Chapter 1 slides, 8th edition (why layering, protocol stack, encapsulation, ISO/OSI)DocsKurose and Ross, hosted by Simon Fraser UniversitySlides 1-66 to 1-68(opens in a new tab)
- Chapter 6 slides, 8th edition (where the link layer is implemented, MAC addresses)DocsKurose and Ross, hosted by Simon Fraser UniversitySlide 6-40 on 48-bit MAC(opens in a new tab)
- RFC 791: Internet ProtocolRFCIETF32-bit addresses (2.3), header (3.1), no retransmission (1.4)(opens in a new tab)
- RFC 9293: Transmission Control Protocol (TCP)RFCIETFObsoletes RFC 793; 16-bit ports, socket pair, TCB, three-way handshake(opens in a new tab)
- RFC 768: User Datagram ProtocolRFCIETF8-octet header(opens in a new tab)
- RFC 1122: Requirements for Internet Hosts, Communication LayersRFCIETFFour-layer suite (1.1.3), relation to OSI(opens in a new tab)
- RFC 6335: IANA Procedures for Service Name and Transport Protocol Port Number RegistryRFCIETFPort ranges (6)(opens in a new tab)
- RFC 6437: IPv6 Flow Label SpecificationRFCIETF5-tuple definition (3)(opens in a new tab)
- RFC 826: An Ethernet Address Resolution ProtocolRFCIETFIP to 48-bit Ethernet address(opens in a new tab)
- X.200: OSI Basic Reference Model, The basic modelDocsITU-TApproved 1994, seven layers(opens in a new tab)
- Guidelines for Use of EUI, OUI, and CIDDocsIEEE Registration AuthorityEUI-48 is six octets, used for MAC addresses(opens in a new tab)
- socket(7), Linux manual pageDocsman7.org (Linux man-pages project)Sockets as the interface between user processes and kernel protocol stacks(opens in a new tab)