A video call, a web page and a mail app on one laptop
You are on a video call. In another tab, a web page is loading, and your mail app is checking for new messages. All of this traffic arrives at the same laptop, with the same IP address. How does the laptop know which bytes belong to the call, which to the browser and which to the mail app?
IP cannot answer that question, because an IP address only identifies a device. The answer comes from the layer above IP: the transport layer, Layer 4 of the OSI model.
Two protocols, two styles of delivery
Start with a browser on PC-1 at 192.168.1.20. It opens a TCP connection from temporary port 52000 to a web service at 203.0.113.10:443. A temporary port is a local port chosen for this conversation. The server's replies are addressed back to port 52000, so the operating system can associate them with the correct socket, its application's network endpoint.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Follow the devices in order. SW1 carries the Ethernet frame across the local LAN. R1 removes that local framing and routes the IP packet to its other interface. In this lab, neither device terminates the browser's TCP connection. The IP addresses identify the endpoints, and TCP ports help identify the application conversation at those endpoints. The exact protocol, local address and port, and remote address and port matter; a port number alone is not the whole connection identity.
The transport layer moves data between two applications, not just two devices. It has two main protocols:
- TCP (Transmission Control Protocol): careful and reliable. It sets up a connection first, numbers every byte and resends anything that gets lost.
- UDP (User Datagram Protocol): simple and lightweight. It sends each message on its own and does not check whether it arrived.
A chunk of data plus a TCP header is called a segment. A chunk of data plus a UDP header is called a datagram. Either one then goes inside an IP packet, which goes inside a frame, such as an Ethernet frame. This wrapping is called encapsulation.
Device key: Media service (server)
Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.
Reading the addresses
IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.
An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.
- Laptop: IP 192.168.1.20
- Web server: TCP 443
- Mail server: TCP 993
- Media service: UDP media
- 1. Web page data arrives for the browser. Its destination port tells the laptop to pass it to the browser.
- 2. Mail data arrives with a different destination port, so it goes to the mail app.
- 3. Video call audio arrives over UDP, with its own port. One IP address, three separate conversations.
Six jobs, and which protocol does each
| Job | What it means | TCP | UDP |
|---|---|---|---|
| Multiplexing | Many applications share one IP address; port numbers keep them apart | Yes | Yes |
| Segmentation | Large data is split into pieces that fit in packets | Yes | No (the application keeps its messages small enough) |
| Connection setup | Both sides agree to communicate before data is sent | Yes (handshake) | No |
| Reliable delivery | Lost data is noticed and sent again | Yes | No |
| Ordering | Data is passed to the application in the order it was sent | Yes | No |
| Flow control | The sender slows down when the receiver cannot keep up | Yes (windowing) | No |
Multiplexing means many conversations share one path. The sending side combines them; the receiving side uses the port numbers to separate them again (demultiplexing).
Why IP needs a layer above it
IP is best effort: it tries to deliver each packet, but it makes no promises. Packets can be lost, arrive twice or arrive in the wrong order, and IP does not resend them. Some applications cannot accept that: a downloaded file with one missing byte is broken. So TCP adds reliability on top of IP.
Some applications value a deadline more than recovering every old message. A voice application may discard a late audio frame rather than delay the conversation. UDP lets the application choose that behaviour, but does not guarantee low delay. Applications can add their own recovery and congestion control over UDP. Choosing TCP or UDP is a design trade-off, not a promise that one is faster in every case.
Seeing Layer 4 on your own computer
You can see the transport layer at work on any computer. The netstat and ss commands list your open connections. Each line shows a protocol (TCP or UDP), a local address and port, and a remote address and port. On a Cisco router, show control-plane host open-ports lists the TCP and UDP ports the router itself is listening on.
On a typical laptop the list is longer than most people expect: background updaters, sync clients and chat apps keep connections open even when nothing seems to be running.
Learn more: Viewing Connections on Your Computer
Test yourself on the transport layer
Your laptop receives two packets with the same destination IP address: one for the browser and one for the mail app. How does it know which application each belongs to?
In a packet capture, you look at a piece of application data with a TCP header in front of it. What is this unit called?
A DNS client and a voice app on the same PC both use UDP at the same time. Which transport layer job does UDP still do for them?
Technical references
RFC 9293: base TCP header, connection state, sequence space and delivery; RFC 768: UDP fields; RFC 8085: application responsibilities over UDP; RFC 9000: QUIC over UDP.