- Published on
Networking by Layer: How an App's Data Reaches the Other Side of the World
- Authors

- Name
- seren-wib
Contents
- 0. At a glance
- Example scenario
- The five layers in one table
- Why split it up
- 1. Mapping the OSI 7 layers to TCP/IP
- 2. Application layer
- The message built in this example
- URL
- HTTP
- TLS
- DNS
- DHCP
- Other application protocols
- Client-server and P2P
- What the application layer cannot do alone
- 3. Between application and transport: socket, operating system, driver, NIC
- Socket
- When sending
- When receiving
- Inter-process communication on the same computer
- 4. Transport layer
- Port numbers and multiplexing
- TCP connection: 3-way handshake
- Sequence numbers, ACK, retransmission
- Flow control and congestion control
- Closing the connection
- UDP
- TCP vs UDP, and QUIC
- What the transport layer cannot do alone
- 5. Network layer
- IP addresses
- Checking whether it is the same network
- Private IP, public IP, NAT
- IPv6
- The IP header and best-effort delivery
- MTU and fragmentation
- Router, default gateway, home router
- Routing and forwarding
- ICMP: ping and traceroute
- Unicast, broadcast, multicast, anycast
- What the network layer cannot do alone
- 6. Between network and link: ARP
- 7. Link layer
- MAC addresses and Ethernet frames
- Switches and bridges
- Shared media and medium access control
- Modern Ethernet: switches and full duplex
- Wi-Fi: CSMA/CA and RTS/CTS
- Every link uses a different technology
- Network scope and topology
- What the link layer cannot do alone
- 8. Physical layer
- Media
- Bits into signals
- Multiplexing
- Full duplex, half duplex, simplex
- Bandwidth, throughput, latency
- Physical layer devices
- What the physical layer cannot do alone
- 9. To the other side of the world: the real structure of the internet
- Access network
- ISP, AS, IXP
- Backbone and submarine cables
- Data centers, load balancers, CDN
- To the friend's phone: once more from the server
- Where delay comes from
- 10. Everything that crosses layers, at once
- Encapsulation and decapsulation
- How far each device opens
- What changes on each link vs what stays
- Protocols that tie layers together
- 11. Numbers table
This post follows a single "Hi" sent from a chat app on a laptop in Seoul to a friend's phone in São Paulo, on the other side of the world, in layer order. The post that follows the same thing in time order (steps 0 to 13) is The Full Path of One Web Request to the Server. That post answers "what happens when". This one answers "who does what". While studying lecture 5 (networking) of Introduction to Computer Systems (컴퓨터시스템개론), I found that writing in lecture order scattered the same layer across many sections, so I regrouped everything by layer.
0. At a glance
Think of a company sending documents overseas. The person in charge writes only the content. The admin team writes the receiving department on the envelope. The mail room attaches the other company's address. The carrier only moves it to the next logistics center. Each team fills in its own box and trusts the rest to others.
From the left: the OSI 7 layers, the TCP/IP layers with their data units and addresses, the headers the sender adds, and what the receiver checks. The red dot is the data being sent.
The teams in the analogy are layers. Wrapping envelope inside envelope is encapsulation. Opening them one by one on the receiving side is decapsulation. The content writer is the application layer, the receiving department is the transport layer's port, the company address is the network layer's IP address, and the transport between logistics centers is the link layer and the physical layer.
How to read the diagram
- Left two columns: which TCP/IP layer each OSI layer falls into. The lecture teaches TCP/IP as 4 layers (link includes physical), but this post splits the physical layer out and uses five slots.
- Middle: the sender. Each layer treats whatever it got from above as plain data and puts its own header in front. The link layer also adds an FCS at the end for error detection.
- Right: the receiver. From the bottom up, each layer checks "is this for me, and is it intact?", strips its header and passes the rest up.
Example scenario
I send "Hi" from a chat app on my laptop at home in Seoul (Wi-Fi) to a friend who lives in São Paulo. The chat app keeps a TLS-protected connection open to a chat server (chat.example.com) in a US data center, and my friend's phone (LTE) keeps a connection open to the same server. The message travels twice: once laptop → server, once server → friend's phone.
| Device | Address (all reserved for documentation or shared use) |
|---|---|
| Laptop (private) | 192.168.0.20, source port 51000 |
| Home router (LAN side) | 192.168.0.1 (default gateway) |
| Home router (public) | 203.0.113.5 |
| Chat server | 198.51.100.10 : 443 |
| Friend's phone (inside carrier) | 100.64.12.34 (behind CGNAT) |
| Friend's carrier NAT (public) | 192.0.2.77 |
The five layers in one table
| Layer | Data unit | Address | Typical devices | Typical protocols | What it cannot do alone |
|---|---|---|---|---|---|
| Application | Message | Domain name (URL) | Hosts (servers, clients) | HTTP, DNS, TLS, SSH, SMTP, DHCP | Actually deliver to the program on the other side |
| Transport | Segment / datagram | Port number | Hosts (only at the end devices) | TCP, UDP (QUIC runs on UDP) | Find a path, hand off to another network |
| Network | Packet | IP address | Routers, home routers, L3 switches | IP, ICMP, OSPF and BGP (route information) | Reliability, actually hand off to the next device |
| Link | Frame | MAC address | Switches, bridges, APs, NICs | Ethernet, Wi-Fi, ARP (ties IP to MAC) | Send outside the same link |
| Physical | Bit (signal) | None | Repeaters, hubs, cables, modems | Signal specs per medium | Know whose bits they are and where they end |
Why split it up
In the words of the lecture slides, it is "organizing complex communication functions by role". In practice you get three things.
- Swappable parts: whether the laptop uses Wi-Fi or wired Ethernet, and whether the friend's phone uses LTE, IP, TCP and HTTP above stay the same. When the link technology changes, you do not have to rewrite the application.
- Peers talk only to the same layer: the sender's TCP talks to the receiver's TCP (sequence numbers, ACK), and the sender's IP talks to the IP of routers on the path (destination IP, TTL). Each header is read only by the same layer on the other side.
- Trust only the layer right below: each layer uses only the service of the layer directly below it. TCP trusts only that "IP sends the packet somewhere", and IP trusts only that "the link hands the frame to the next device".
The textbook definitions of the OSI 7 layers and encapsulation are in my networking class notes.
1. Mapping the OSI 7 layers to TCP/IP
OSI is a reference model made by the International Organization for Standardization (ISO), and the real internet runs on TCP/IP. OSI is a framework for "how to think about dividing the functions", and TCP/IP is the set of protocols actually used that fits that framework.
| OSI | TCP/IP (4 layers, lecture) | This post (5 slots) | What goes in this layer |
|---|---|---|---|
| 7 Application | Application | Application | HTTP, DNS, SMTP, SSH |
| 6 Presentation | Application | Application | Character encoding (UTF-8), compression, encryption (part of TLS) |
| 5 Session | Application | Application | Keeping connection state (TLS session, HTTP keep-alive, login session) |
| 4 Transport | Transport | Transport | TCP, UDP |
| 3 Network | Network (internet) | Network | IP, ICMP |
| 2 Data link | Link | Link | Frames and MAC of Ethernet and Wi-Fi (802.11) |
| 1 Physical | Link | Physical | Cables, connectors, voltage, light, radio, bit encoding |
- TCP/IP has no separate presentation or session layer. The application or a library (a TLS library, for example) handles that work itself.
- TLS is hard to place. It sits above TCP and below HTTP and does encryption (presentation) and session management (session), so in OSI terms it spans layers 5 and 6. In TCP/IP it is usually put in the application layer.
- The numbers in "L2 switch", "L3 switch", "L4 load balancer" and "L7 load balancer" are OSI numbers. They mean how far up the headers a device reads.
2. Application layer
This is the person writing the letter. They decide what to say and in what format, but they do not know which road the post office takes. The application layer defines the format of messages and the order in which they are exchanged, and the protocol is the rulebook of that service.
- Data unit: message. An HTTP request or response, a DNS query or answer, one email.
- Address: domain name. It is a name for people, and DNS turns it into an IP address before it is handed to the layers below.
- Devices: hosts at the ends (laptops, phones, servers). Routers in the middle do not open the application layer.
The message built in this example
Say the chat app keeps a WebSocket connection open to the server and sends messages as JSON.
{ "type": "send", "to": "friend-42", "text": "Hi" }
- The app turns this string into UTF-8 bytes (presentation layer work).
- It adds a WebSocket frame header.
- TLS encrypts it into a TLS record.
- It hands those bytes to the socket. From here on it is the transport layer.
WebSocket starts with one HTTP request (Upgrade: websocket), then keeps that TCP connection open so either side can send messages at any time. That open connection is also why the server can push "Hi" to the friend's phone first. If the phone app is closed, the server hands the notification to the OS vendor's push service (APNs, FCM).
URL
https://chat.example.com/rooms/7?since=100#latest
| Part | Name | Meaning |
|---|---|---|
https | Scheme | How to access it. It sets the default port (https 443, http 80) |
chat.example.com | Host | Domain name. DNS finds its IP |
/rooms/7 | Path | The resource requested from the server. It may differ from the server's real file path |
?since=100 | Query | Extra information passed to the server |
#latest | Fragment | A position inside the document. It is not sent to the server |
A domain name gets more specific from right to left. com is the top-level domain, example.com is the registered domain, and chat is a name under it. The dots in a domain name have nothing to do with the dots in an IP address.
HTTP
The request-response rules used by the web and most app APIs.
- Request: method (GET read, POST submit, PUT replace, DELETE delete) + path + version, headers (
Host,Cookie,Content-Type), body. - Response: status code + headers + body (HTML, JSON, images).
| Status code range | Meaning | Examples |
|---|---|---|
| 2xx | Success | 200 OK |
| 3xx | Elsewhere or further action | 301, 302, 304 |
| 4xx | Problem with the client request | 401, 403, 404 |
| 5xx | Problem processing on the server | 500, 502, 503 |
- Stateless: HTTP itself does not remember earlier requests. Login state is kept by the browser attaching the cookie the server gave it to every request (the server uses the cookie value to find the session).
- Versions: HTTP/1.1 sends requests one after another on a connection (reusing the connection with keep-alive), HTTP/2 sends many requests at once as streams over one TCP connection, and HTTP/3 uses QUIC over UDP instead of TCP.
TLS
This is putting the envelope in a safe and sending it so that only the recipient has the key. TLS, on top of a TCP connection, gives server authentication (certificates), confidentiality (encryption) and integrity (tamper detection). HTTPS = HTTP + TLS.
- The TLS 1.3 handshake takes 1 RTT. ClientHello (supported ciphers, key exchange value, SNI) → ServerHello + certificate + signature + Finished → both sides compute the same session key. The key itself never goes over the network (ECDHE).
- After that, application data is encrypted symmetrically with the session key. Routers, home routers and ISPs in the middle cannot read inside TLS records.
- What it does not protect: whether the site's content is genuine. Phishing sites use HTTPS too. The step-by-step process is in TLS setup.
DNS
It is a phone book. Give it a name and it tells you the number, but it does not make the call for you. DNS (Domain Name System) is a distributed database that finds the records attached to a domain name. It is not a system that carries web pages or messages.
| Record | Content |
|---|---|
| A | IPv4 address |
| AAAA | IPv6 address |
| CNAME | Alias for another name (often used to hook up a CDN) |
| MX | Server that receives mail |
| NS | Authoritative DNS server for this domain |
| TXT | Arbitrary string (domain ownership checks, mail auth policy) |
Lookup order:
- App → the OS stub resolver. It checks the browser cache, the OS cache and the
hostsfile first. - If not found, it asks the recursive DNS resolver (the DNS server received via DHCP, usually the ISP or home router, or a public DNS). Usually UDP 53, TCP 53 for large answers. To encrypt it, DoT (TLS, 853) or DoH (HTTPS, 443).
- The resolver asks in turn on your behalf. Root server ("
.comis over there") → TLD server ("example.comis over there") → authoritative server ("the A record forchat.example.comis 198.51.100.10"). - The resolver caches the record for its TTL. The next person gets it right away.
- One name can have several IPs, and it can return different IPs depending on where you ask from. This is used for load balancing, failover and picking a nearby CDN server.
- There are 13 root server names, but far more actual servers around the world. They use anycast, advertising the same IP from many places, so the nearest one answers.
- DNS itself is an application layer protocol, and its query packets go through the lower layers just the same. The time order is in DNS: name → IP.
DHCP
When the laptop first joins the home Wi-Fi, it knows neither its own IP, nor the gateway, nor the DNS server. DHCP hands these out automatically. Discover → Offer → Request → Ack, DORA for short.
- What it gets: IP address (192.168.0.20), subnet mask (/24), default gateway (192.168.0.1), DNS server, lease time.
- It has no IP yet, so it asks by broadcast from 0.0.0.0 → 255.255.255.255, UDP 68 → 67.
- The protocol is an application layer protocol running on UDP, but what it does is configure the network layer. It is a classic case of crossing layers, so it appears again in the table in section 10. The step-by-step process is in DHCP.
Other application protocols
| Protocol | What it does | Port (transport) | Encryption |
|---|---|---|---|
| SSH | Remote shell, running commands, tunnels | 22 (TCP) | Yes |
| Telnet | Remote shell (old way) | 23 (TCP) | None, unfit for the internet |
| SMTP | Sending mail (app → server, server → server) | 25 server to server, 587 submission (TCP) | Added with STARTTLS |
| IMAP | Reading server mail synced across several devices | 143, 993 TLS (TCP) | 993 is TLS |
| POP3 | Pulling server mail down to a device | 110, 995 TLS (TCP) | 995 is TLS |
| FTP | File transfer (separate control and data connections) | 21 control (TCP) | None |
| SFTP | File transfer over an SSH channel | 22 (TCP) | SSH encryption |
| DNS | Name lookup | 53 (UDP, TCP for large answers) | Added with DoT and DoH |
| DHCP | Automatic address configuration | 67 and 68 (UDP) | None |
The steps by which an SSH connection opens are written up separately in Connecting over SSH.
Client-server and P2P
| Aspect | Client-server | P2P |
|---|---|---|
| Relationship | The requesting side and the providing side are separate | Participants both request and provide |
| Examples | The web, the chat server in this example | BitTorrent, direct connections in video calls (WebRTC) |
| Hard parts | Scaling the server, handling failures | Participants come and go at any time, getting through NAT |
One reason the laptop goes through the server instead of sending straight to the friend's phone is NAT. Both are behind NAT, so neither can open a connection to the other first (section 5, NAT). Video call apps use STUN to learn their outside address and try a direct connection, and relay through a TURN server if that fails.
What the application layer cannot do alone
- Actually deliver to the program on the other side: the application layer only knows "this message to chat.example.com". Making the bytes arrive in order with nothing missing is the transport layer's (TCP's) job.
- Point to which program on the same computer: that is done by the port number, that is, the transport layer.
- Find a path by name: routers do not know names. The app has to get the IP from DNS and pass it down so the network layer can find a path.
3. Between application and transport: socket, operating system, driver, NIC
A restaurant customer only hands an order slip in at the counter. They do not need to know how the kitchen runs or which road the delivery rider takes. For an application, that counter is the socket.
The sending host is on the left, the receiving host on the right. Above the dotted line is user space, the middle is the kernel, and the bottom is hardware.
The counter is the socket, the kitchen is the TCP/IP stack inside the operating system kernel, the staff member who hands packages to the rider is the device driver, and the delivery motorbike is the NIC.
Socket
- It is the network communication interface the operating system provides. A program deals only with the socket and never touches the NIC or driver directly.
- A socket is identified by five values, (protocol, my IP, my port, peer IP, peer port), the 5-tuple. On the laptop side it is (TCP, 192.168.0.20, 51000, 198.51.100.10, 443).
- Client call order:
socket()→connect()(the TCP handshake happens here) →send()/recv()→close(). - Server call order:
socket()→bind(443)→listen()→accept()(a new socket per connection) →recv()/send().
When sending
- The app calls
send(). A system call switches from user mode to kernel mode. - The kernel copies the bytes into the socket's send buffer.
send()returning does not mean the peer received it. It only means the data went into the buffer. - TCP cuts the buffer contents into segments no larger than the MSS, and keeps a copy until it gets an ACK.
- IP looks at the routing table, picks the outgoing interface and next hop, and adds the IP header.
- It finds the next hop's MAC in the ARP cache and builds the frame header.
- The device driver puts the frame on the transmit ring buffer (TX ring) and tells the NIC "there is something to send".
- The NIC reads the frame straight from memory by DMA and adds the FCS, and the PHY (the physical layer circuit) turns the bits into a signal and sends it out.
Modern NICs often take over checksum calculation (checksum offload) and even cutting large data into segments (TSO). The layer split is logical, and which chip actually does the work varies by implementation.
When receiving
- The NIC turns the signal into bits and checks that the destination MAC is its own (or broadcast) and that the FCS is correct.
- It writes the frame into the receive ring buffer (RX ring) by DMA and raises an interrupt. When packets pile up, interrupts are reduced and the driver collects them in batches (Linux NAPI).
- The driver hands the frame to the kernel, and the kernel passes it up, checking the Ethernet header → IP header → TCP header in turn.
- TCP finds the socket by its 5-tuple, puts things in order, sends an ACK, and puts the bytes into the socket's receive buffer.
- It wakes up the server process waiting in
recv(). The process reads the bytes from the buffer.
Interrupts and DMA themselves are the same story as lecture 3 (I/O control) of Introduction to Computer Systems. The CPU does not move bytes one at a time. The device writes into memory directly and signals when it is done.
Inter-process communication on the same computer
Processes cannot read each other's memory directly. On the same computer they use shared memory, pipes and message passing provided by the OS. On different computers they use a socket, naming an IP and port, and send over the network. Even on the same computer you can use a socket on 127.0.0.1 (loopback), and then the packet never goes down to the NIC. It loops back inside the kernel.
4. Transport layer
This is splitting the contents of a parcel into several boxes, with the receiver putting them back together by number and asking again for any missing box. The transport layer connects a program on one end host to a program on the other. Routers in the middle do not process this layer.
- Data unit: a segment for TCP, a datagram for UDP. (An IP packet's formal name is also an IP datagram, which is confusing, but in this post a datagram is the UDP unit.)
- Address: port number (16 bits, 0 to 65535).
- Devices: end hosts only. The exceptions are devices that read or rewrite ports, such as NAT routers, firewalls and L4 load balancers.
Port numbers and multiplexing
Once you reach the apartment building's address (IP), the unit number (port) is what is left.
| Range | Name | Examples |
|---|---|---|
| 0 to 1023 | Well-known ports | 22 SSH, 53 DNS, 80 HTTP, 443 HTTPS |
| 1024 to 49151 | Registered ports | 3306 MySQL, 5432 PostgreSQL |
| 49152 to 65535 | Dynamic (ephemeral) ports | Client source ports |
- The client's source port is picked by the OS on the spot (ephemeral port). The Linux default range is 32768 to 60999, a little different from the IANA range.
- Multiplexing: sending the data of many apps out through one IP. Demultiplexing: handing each received segment to the right socket by port (by the whole 5-tuple for TCP). Even with tens of thousands of clients on the server's single port 443, every 5-tuple is different, so nothing gets mixed up.
TCP connection: 3-way handshake
- Laptop → server: SYN (seq = x, options such as MSS and window scale)
- Server → laptop: SYN+ACK (seq = y, ack = x + 1)
- Laptop → server: ACK (ack = y + 1)
It does not lay down a wire. It creates state in both kernels saying "talking with this peer, sequence numbers start here". This costs 1 RTT, and TLS 1.3 costs 1 more RTT before the first message goes out. The textbook explanation is in three-way handshake process.
Sequence numbers, ACK, retransmission
B was dropped in a router queue on the way. Even after receiving C, D and E, the server cannot hand them to the app and just repeats "give me from byte 101" (ACK 101). The laptop sees three duplicate ACKs and resends B.
- Sequence number: numbers are put on bytes, not segments. seq is the number of the first byte in that segment.
- Acknowledgment (ACK): "I have everything before byte n". It is a cumulative ACK.
- Retransmission: two signals reveal a loss.
- Byte stream: even if the app sends "HELLO" and "WORLD" separately, the receiver may read "HELLOWORLD" in one go. TCP keeps order but does not keep message boundaries. That is why chat apps use their own boundary markers, such as a length field or WebSocket frames.
- Checksum: computed over the TCP header + data + part of the IP addresses (pseudo-header). Corrupted segments are dropped, and retransmission fills the gap. The calculation is in The Internet Checksum.
This is the same idea as the ARQ from the computer networks course. The difference is scope. Link layer ARQ covers one hop to the next device, while TCP covers end to end, from the laptop in Seoul to the server in the US.
Flow control and congestion control
Both mean "slow down sending", but for different reasons.
| Aspect | Flow control | Congestion control |
|---|---|---|
| Protects | The receiver's receive buffer | The network in between (router queues) |
| Signal | The receive window the receiver writes in ACKs | Packet loss, rising delay |
| Knob | rwnd | The congestion window the sender sets on its own |
| Behavior | When the buffer fills, shrink rwnd to say "stop sending" | At first double cwnd every RTT (slow start), cut it sharply on loss |
- The amount that can be sent without an ACK at one time (in flight) is min(rwnd, cwnd). This "send while sliding the window" is the sliding window.
- Congestion control algorithms differ by OS. Reno's AIMD (increase a little at a time, cut in half) is the basic form, Linux defaults to CUBIC, and BBR, which sets the rate by watching delay, is also used.
- My class notes are in flow control and congestion control.
Closing the connection
FIN → ACK, FIN → ACK: each side announces "nothing more to send" on its own (4-way). The side that closes first waits in TIME_WAIT for twice the maximum segment lifetime (2MSL). This keeps late old segments from mixing into a new connection with the same 5-tuple.
UDP
This is writing only the address on an envelope and dropping it in a mailbox. No delivery confirmation, no order.
- 8 B header: source port, destination port, length, checksum. That is all.
- No connection setup, no ordering guarantee, no retransmission. In exchange, it keeps message boundaries. One datagram sent arrives as is in one
recv()on the receiving side. - Where it is used: DNS queries (one question, one answer), DHCP, voice and video calls, games (stale position data is better thrown away), and QUIC.
TCP vs UDP, and QUIC
| Comparison | TCP | UDP |
|---|---|---|
| Connection setup | Required (3-way handshake) | None |
| Delivery form | Byte stream | Independent datagrams |
| Ordering guarantee | Yes | No |
| Retransmission | Yes | No |
| Message boundaries | Not kept | Kept |
| Flow and congestion control | Yes | No (up to the app) |
| Header size | 20 B or more | 8 B |
| Examples | Web (HTTP/1.1, HTTP/2), SSH, mail | DNS, real-time voice and video, games |
QUIC is a protocol that implements sequence numbers, retransmission, congestion control and TLS 1.3 encryption itself on top of UDP. HTTP/3 uses it. TCP lives inside the OS kernel and is hard to change, and when one segment goes missing, every stream behind it waits (head-of-line blocking). QUIC retransmits per stream, finishes connection setup and encryption setup in one go, and can be updated together with the app. This choice is an extension of TCP vs UDP. Even on UDP, you can build reliability on top.
What the transport layer cannot do alone
- Find a path: TCP only knows the peer's IP, not which routers to pass through from Seoul to the US. The network layer does that.
- Negotiate with devices in the middle: TCP runs only at the two ends. Even if a router in the middle drops a packet, TCP only knows it as "no ACK is coming". This is the end-to-end principle. Do the complex work at the ends and keep the middle simple.
- What it gives the layer above: on top of unreliable IP, it builds "in order, nothing missing" (TCP). Or just fast (UDP).
5. Network layer
This is the international postal system. It looks only at the recipient's address on the envelope and decides "which sorting center does this letter go to next". It does not check whether the letter arrived. The network layer moves packets across different networks to the destination host, and its protocol is IP alone.
- Data unit: packet (IP datagram).
- Address: IP address. It is a logical address, so it changes with the network configuration. Take the laptop to a café and its IP changes.
- Devices: routers (the router function inside a home router, ISP routers, L3 switches in data centers).
IP addresses
IPv4 splits 32 bits into four groups of 8 bits and writes each as 0 to 255. The front network part says which network, and the back host part says which device inside it. The boundary is shown by a prefix length or a subnet mask. Both carry the same information.
| Prefix | Subnet mask | Host bits | Usable hosts |
|---|---|---|---|
| /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 |
The host count is reduced by 2 because the address with the host part all 0s (the network address) and the one with all 1s (the broadcast address) cannot be given to devices. How to split them is in subnetting and subnet mask.
Checking whether it is the same network
Before sending a packet, the laptop first checks "is the peer on the same network as me?". It ANDs my IP and the peer's IP with the subnet mask and compares the network addresses.
Laptop 192.168.0.20 AND 255.255.255.0 = 192.168.0.0
Server 198.51.100.10 AND 255.255.255.0 = 198.51.100.0 → different → to the default gateway
- If they match, it finds the peer's MAC with ARP and sends directly inside the LAN. No router involved.
- If they differ, it sends to the default gateway (192.168.0.1). The destination IP stays the server, and only the frame's destination MAC is the gateway.
- The IP address alone cannot decide it. 192.168.1.20 and 192.168.2.30 are on the same network with /16 and on different networks with /24.
To a PC on the same LAN, traffic passes only through the AP and switch. To another IP network, it goes through the gateway (router). Joining Wi-Fi and Ethernet (the AP) and joining IP networks (the router) are different jobs.
Private IP, public IP, NAT
- Private IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Used inside homes, schools and companies, and another home may reuse the same addresses. Internet routers hold no routes to these addresses.
- Public IPv4: addresses assigned so they never overlap across the whole internet. Having a public IP does not mean it can always be reached from outside (firewalls).
- NAT (Network Address Translation): the home router rewriting the private source IP of outgoing packets to its public IP. Since several devices in the home share one public IP, it rewrites ports too (NAPT, PAT).
| Direction | Before (source) | After (source) | What stays in the translation table |
|---|---|---|---|
| Outbound | 192.168.0.20 : 51000 | 203.0.113.5 : 40001 | 40001 ↔ 192.168.0.20:51000, peer 198.51.100.10:443 |
| Inbound | Destination 203.0.113.5 : 40001 | Destination 192.168.0.20 : 51000 | Reversed by looking up the table |
- NAT rewrites both the IP header and the TCP header (ports) and recomputes the checksums. It is the classic "layer violation", where a network layer device reaches into the transport layer.
- A connection that starts from outside has no entry in the translation table, so it is dropped. To reach a home PC from outside, you have to set up port forwarding. This is also why P2P is hard. The way to connect devices behind NAT without port forwarding is an overlay network.
- Because public IPv4 addresses are scarce, carriers give private addresses to subscribers too and do NAT once more on carrier equipment. This is CGNAT (Carrier-Grade NAT), and it uses the dedicated range 100.64.0.0/10. The friend's phone in this example is one of these.
- Everything that happens in the home router is in Router: firewall + routing + NAT.
IPv6
- 128 bits. Written as eight groups of 16 bits in hexadecimal, separated by colons. Leading zeros are dropped, and one run of all-zero groups can be shortened to
::once.2001:0db8:0000:0000:0000:0000:0000:0010→2001:db8::10. - Addresses are plentiful, so in principle NAT is not needed. Each device gets a public address, and the firewall blocks connections coming from outside.
- The header is a fixed 40 B, has no header checksum (the link and transport layers already check), and routers do not fragment. The TTL is called Hop Limit.
- It uses ICMPv6 Neighbor Discovery instead of ARP, and multicast instead of broadcast.
- Today dual stack, running IPv4 and IPv6 together, is the norm. When DNS returns both A and AAAA, the OS picks. More detail is in IPv6.
The IP header and best-effort delivery
Picking only the IPv4 header fields that come up in this post gives the following. Without options it is 20 B.
| Field | What it does |
|---|---|
| Version | 4 or 6 |
| Total length | Header + data length |
| Identification, flags, offset | Used to reassemble fragments. DF bit = do not fragment |
| TTL | Decreases by 1 at each router, dropped at 0. Keeps packets from looping forever |
| Protocol | Who the upper layer is. 1 ICMP, 6 TCP, 17 UDP |
| Header checksum | Checks the header only. Recomputed at every router because TTL changes |
| Source and destination IP | End-to-end addresses |
IP is best-effort delivery. It tries hard to send toward the destination, but it does not guarantee arrival, order or no duplicates. When a router queue fills, it just drops. TCP above does the recovery. The default TTL differs by OS (Linux and macOS 64, Windows 128).
MTU and fragmentation
- Each link has a maximum size it can carry in one frame. For Ethernet it is 1500 B, and this is called the MTU.
- TCP cuts data to the MSS or less from the start (usually 1500 − IP 20 − TCP 20 = 1460 B).
- If there is a hop with a smaller MTU along the way (a VPN tunnel, PPPoE 1492 B), one of two things happens.
- In IPv4, if DF is off, the router fragments the packet and the destination host reassembles it. If even one fragment is lost, the whole thing is thrown away.
- If DF is on, the router drops it and sends ICMP "Fragmentation Needed". The sender reduces the size. This is Path MTU Discovery. IPv6 always works this way.
Router, default gateway, home router
- Router: a device that looks at IP addresses and passes packets between different networks. It strips the received frame to take out the IP packet, looks at the destination IP to pick the outgoing interface and next hop, decrements TTL by 1, and builds a new frame that fits the outgoing link.
- Default gateway: from the host's point of view, the IP of the router interface where "anything for another network goes first". At home it is the LAN-side address of the home router.
- Home router: a product that puts router + Ethernet switch + wireless AP + DHCP server + NAT + firewall in one box. "Home router" is a product name, and router, switch and AP are functions inside it.
Routing and forwarding
On the left is routing, which builds route information. On the right is forwarding, which uses that table for each packet. The red line is the actual path to 198.51.100.10.
In navigation terms, downloading the map ahead of time and turning the wheel at an intersection after reading the sign are different jobs. The first is routing, the second is forwarding.
- Routing (control plane): routers exchange route information to build and update routing tables. Slowly, in the background.
- Forwarding (data plane): every time a packet arrives, look up the table by destination IP and pass it to the next hop. Router hardware does this at line rate.
- longest prefix match: if several entries contain the destination IP, pick the one with the longest (most specific) prefix. In the diagram, 198.51.100.10 matches /0, /22 and /24, but /24 wins. If nothing matches, the default route (0.0.0.0/0) is used.
- AS: a group of networks run by one organization under one policy. One ISP or one large cloud is each an AS and gets an AS number.
- Inside an AS (IGP): OSPF is the typical one. Each router floods its link costs to the whole AS (link-state), and each computes the shortest paths with Dijkstra. The older RIP is a distance-vector protocol that only counts hops and works only up to 15 hops. The comparison is in RIP vs OSPF.
- Between ASes (EGP): only BGP is used. It advertises AS paths such as "this prefix is reachable via AS 64497 → 64498" (path-vector). Policy comes before shortest path. For example, it prefers a partner it exchanges with for free (peering) over an upstream provider it pays (transit). BGP runs on TCP 179. A routing protocol, too, ends up exchanging messages over the lower layers like an application.
- So a router does not compute the fastest path in real time every time. It just looks at a table built in advance, and because of policy that table may send traffic on a geographically roundabout path. How the table is organized is in routing table.
ICMP: ping and traceroute
ICMP is a helper protocol of IP. It rides inside IP packets (protocol number 1), but it is not a transport layer protocol. It is for network layer control and error reporting.
| ICMP message | When |
|---|---|
| Echo Request / Reply | ping |
| Time Exceeded | When TTL hits 0 and the packet is dropped |
| Destination Unreachable | No route, port closed, and so on |
| Fragmentation Needed (Packet Too Big) | DF set but larger than the MTU (PMTUD) |
ping: sends an Echo Request and measures the time until the Reply (RTT). If a firewall blocks ICMP, there is no reply even when the server is up.traceroute(tracert): sends with TTL 1, 2, 3 and so on. Each router where TTL hits 0 sends back Time Exceeded, so collecting those source IPs reveals the path. macOS and Linux use UDP as the probe by default, Windows uses ICMP Echo. Routers that do not reply show up as* * *.
Unicast, broadcast, multicast, anycast
| Method | Target | Examples |
|---|---|---|
| Unicast | One specific host | Every chat packet in this example |
| Broadcast | Everyone on the same LAN (does not cross routers) | ARP request, DHCP Discover |
| Multicast | Only hosts that joined the group | IPTV, IPv6 neighbor discovery |
| Anycast | The nearest of several places using the same address | Root DNS, public DNS, CDN |
What the network layer cannot do alone
- Reliability: it does not know if a packet was dropped, delayed or reordered. TCP fills the gap.
- Telling programs apart: IP only gets you to the host. Which program it is, is the port (transport layer).
- Actually handing off to the next device: a router only decides "the next hop is 192.168.0.1". Finding that device's MAC (ARP), putting the packet in a frame and sending it onto the cable is the link and physical layers' work.
6. Between network and link: ARP
It is like announcing in an apartment complex "who lives in unit 302?" and that person raising a hand. You use it when you know the IP address (unit 302) but not the face (MAC) whose door you actually knock on.
ARP (Address Resolution Protocol) is the protocol that finds a MAC address from an IP address within the same LAN.
- The laptop checks its ARP cache. If it has the MAC of gateway 192.168.0.1, done.
- If not, it broadcasts an ARP request. Destination MAC
FF:FF:FF:FF:FF:FF, content "who has 192.168.0.1?". - The home router sends an ARP reply with its own MAC by unicast.
- The laptop stores it in the cache and removes it after a while.
- ARP is not carried in an IP packet but directly in an Ethernet frame (EtherType 0x0806, IPv4 is 0x0800). That is why it is sometimes called layer 2.5.
- What the laptop looks up with ARP is the gateway's MAC, not the server's. The server is on another network, so a broadcast on the same LAN cannot reach it. Each router looks up the next hop's MAC with ARP again.
- ARP has no authentication, so another device on the same LAN can send a fake reply (ARP spoofing). This is one reason TLS matters on public Wi-Fi.
- The time order is in ARP.
Client → router A → router B → web server (Ethernet, no NAT). Every time the link changes, the frame's MACs are rebuilt, and the IP packet travels on unchanged except for a lower TTL.
7. Link layer
This is local delivery within the neighborhood. It is only responsible up to the next sorting center. At the next center a new waybill is attached. The link layer hands a frame to the neighboring device over one directly connected hop (a link).
- Data unit: frame.
- Address: MAC address. It only means something within the same link.
- Devices: switches, bridges, wireless APs, NICs.
MAC addresses and Ethernet frames
- MAC address: 48 bits, six hex groups like
00:1A:2B:3C:4D:5E. The first 24 bits (OUI) are the manufacturer, the last 24 bits are a serial number. It is burned into the NIC but can be changed in software, and modern phones sometimes use a random MAC per Wi-Fi network. - IP and MAC cannot stand in for each other. IP is "where is the final destination", MAC is "who receives it on this link right now". The comparison is in MAC address.
| Ethernet frame field | Size | Content |
|---|---|---|
| Preamble + SFD | 8 B | A 1010… pattern that syncs the receiver's clock and marks the start (physical side) |
| Destination MAC | 6 B | The receiving NIC (a switch picks the port by this alone) |
| Source MAC | 6 B | The sending NIC (a switch learns locations from this) |
| EtherType | 2 B | What is inside. 0x0800 IPv4, 0x86DD IPv6, 0x0806 ARP |
| Payload | 46 to 1500 B | The IP packet. Padded up to 46 B if short |
| FCS | 4 B | CRC-32 error detection |
If the FCS does not match, the frame is silently dropped. Ethernet does not resend. TCP does the retransmission. The CRC calculation is in CRC, and the general structure of a frame and FCS is in HDLC frame structure.
Switches and bridges
When a frame PC A sent to the server comes in on port 1, the switch learns "PC A = port 1" and sends it out only on port 3, where the server is.
- Bridge: a device that joins two segments of a LAN. If the destination is on the same segment it does not forward, and it forwards only when the destination is on the other segment.
- Switch: a bridge with many ports. Every time a frame comes in, it writes (source MAC, incoming port) into the MAC address table, looks up the destination MAC in the table and sends only out of that port.
- A destination not in the table is sent out of every port except the incoming one (flooding). When the reply comes, the table fills in. Broadcast frames (
FF:FF:FF:FF:FF:FF) also go out of every port except the incoming one. - When frames pile up for the same output port, they wait in a queue, and when the queue is full they are dropped. In modern wired LANs, loss comes from this congestion, not from collisions.
- VLAN: logically splitting one switch into several LANs. Frames get a 4 B tag (802.1Q) to tell them apart. Traffic between VLANs has to go through a router (L3).
- AP: a bridge that converts between wireless frames (802.11) and wired Ethernet frames. It is not a router. So traffic within the same LAN that only passes through an AP needs no router.
Shared media and medium access control
When several devices share one cable or one wireless channel, signals overlap if two devices talk at the same time. The rules that decide who talks when are Medium Access Control (MAC). The MAC in MAC address is this MAC.
- CSMA/CD (Collision Detection): used in old shared-medium Ethernet (coaxial cable, hubs).
- Listen (carrier sense). If it is idle, send.
- Keep listening while sending, and if the signals overlap, treat it as a collision, stop, and send a jam signal.
- Wait a random time and send again. If collisions repeat, double the waiting range each time (binary exponential backoff).
- Why do collisions happen if you checked before sending? Because a signal takes time to reach the end of the cable. If the other side already started but its signal has not reached me yet, I think the line is idle. The 64 B minimum Ethernet frame is also a length chosen "so a collision can be noticed while still sending".
Modern Ethernet: switches and full duplex
| Aspect | Shared-medium Ethernet (past) | Switched Ethernet (modern) |
|---|---|---|
| Connection | Many devices on one medium | A separate link from each device to the switch |
| Communication | Half duplex | Full duplex |
| Collisions | Happen | Generally do not happen |
| Access control | CSMA/CD | Not used |
| Main problem | Collisions | Switch output port congestion and queue loss |
There are only two devices on a link (my NIC and the switch port), and the transmit and receive lines are separate, so sending and receiving at the same time do not overlap. That is why CSMA/CD is not needed.
Wi-Fi: CSMA/CA and RTS/CTS
Wireless is still a shared medium, and you cannot listen while sending. Your own transmit signal is so strong that you cannot hear others' weak signals. So instead of detecting collisions, it avoids them.
The dotted circles are how far each station's signal reaches. A and B both reach the AP but cannot hear each other. Even while A is sending, B judges the channel idle, and the two signals overlap at the AP.
How CSMA/CA (Collision Avoidance) works:
- Listen to see whether the channel is in use.
- If it is, wait until it is free.
- Even after it has been idle for a set time (DIFS), do not send right away. Wait a further random backoff. Even if several stations decide "idle" at once, their start times spread out.
- Send.
- After a short gap (SIFS), the AP sends a link layer ACK.
- If there is no ACK, treat it as a collision or error and resend. Unlike Ethernet, Wi-Fi retransmits at the link layer. Loss is common on wireless, so leaving it to TCP would be too slow.
RTS/CTS is an extra step that reduces the hidden terminal problem.
- A sends an RTS (may I send? + how long it will take) to the AP.
- The AP answers with a CTS (go ahead + how long it will take).
- Every station in the AP's range hears the CTS and stays quiet for that time (setting the NAV). B, which cannot hear A, can hear the AP, so it stops.
- A sends the data and the AP ACKs.
- Limits: two extra frames add cost. So it is turned on only for large frames, or turned off. RTS frames can collide with each other too (but they are short, so the loss is small).
- A Wi-Fi frame has up to 4 address fields (receiving wireless device, sending wireless device, final destination, original source). The AP turns these into the 2 addresses of an Ethernet frame and passes it to the wired side.
- A Wi-Fi connection itself is only the laptop ↔ AP hop. Even if Wi-Fi is connected, the internet will not work if the ISP or server side is down.
Every link uses a different technology
The links one message passes through from the laptop in Seoul to the phone in São Paulo all use different technologies. The IP packet is the same, and only the frame carrying it changes on each link.
| Hop | Link technology | Access method |
|---|---|---|
| Laptop ↔ home router | Wi-Fi (802.11) | CSMA/CA, link ACK |
| Home router ↔ carrier | Fiber access network (FTTH, PON) | Downstream is broadcast to all and each decrypts only its own, upstream gets time slots assigned by the OLT (TDMA) |
| Carrier internal, backbone, undersea hops | Ethernet over optical fiber (point-to-point) | Full duplex, no access control |
| Friend's phone ↔ base station | LTE / 5G | The base station assigns time and frequency resources to each device (scheduling). No CSMA |
| Other access methods | DSL (phone line), cable internet | Reuse existing phone and cable TV lines |
Mobile networks do not "listen and send when idle" like Wi-Fi. The base station tells each device "you, at this time, on this frequency". That is why hundreds of devices on one base station can share it without collisions.
Network scope and topology
PAN (around the body, Bluetooth), LAN (home, building), MAN (city), WAN (country, continent). As the scope grows, the link technology and the operator change.
The shape in which devices and connections are laid out. Modern LANs are stars and trees with a switch in the middle, and the internet backbone is closer to a mesh with many paths.
Topology is viewed in two ways: physical (how the cables are actually laid) and logical (how data flows). Star wiring tied together by a hub is physically a star but logically works like a bus, with everyone sharing the same medium.
What the link layer cannot do alone
- Send outside the link: a MAC only works within the same link. To go to another network you need IP and routers. Each time it passes a router, the frame is rebuilt.
- End-to-end reliability: it only goes as far as dropping corrupted frames by FCS (Wi-Fi retransmits only within that link). The whole way from Seoul to the US is TCP's job.
- Turn bits into signals: turning a frame into voltage, light or radio is the physical layer.
8. Physical layer
This is turning letters into Morse code and blinking a flashlight. It does not know who is writing to whom. It only blinks 0s and 1s at a set beat. The physical layer turns bits into signals on the medium and reads them back as bits.
From the top: bits, NRZ (voltage high and low), Manchester (a rise or fall in the middle of each bit), light on and off, and radio phase. The red line is the position of the bit being sent now.
Morse code is encoding and modulation, the flashlight is the transmitter (the NIC's PHY, a laser, an antenna), and the beat is the bit time (clock).
- Data unit: bit. In practice, one symbol (a single piece of signal) carries several bits.
- Address: none.
- Devices: repeaters, hubs, cables, connectors, modems, ONTs, optical transceivers, antennas.
Media
| Medium | Signal | Characteristics | Where it is used |
|---|---|---|---|
| Twisted pair | Voltage | Cheap and easy to handle, about 100 m, twisting cancels noise | Ethernet inside buildings |
| Coaxial cable | Voltage | Good shielding | Cable TV and internet, old Ethernet |
| Optical fiber | Light | High bandwidth and low attenuation, tens of km without repeaters, no electromagnetic noise | Access networks, backbone, submarine cables |
| Wireless (radio) | Radio | Mobility, but a shared medium with heavy noise, attenuation and interference | Wi-Fi, LTE/5G, Bluetooth |
The detailed characteristics of each medium are in Twisted Pair, Coaxial Cable and Optical Fiber. Attenuation, the weakening of a signal over distance, is in Attenuation.
Bits into signals
- Even for the same 0101, both sides must agree in advance on the shape of the signal.
- NRZ: 1 is high voltage, 0 is low voltage. Simple, but when 0s or 1s run long, the signal does not change and the receiver loses the beat.
- Manchester: the signal always changes in the middle of each bit (rising is 1, falling is 0, per 802.3). Since it changes every bit, the receiver resyncs its clock there. 10 Mbps Ethernet (10BASE-T) used it. In exchange, the signal changes twice as often and uses more bandwidth.
- Fast links put several bits in one symbol. Gigabit Ethernet (1000BASE-T) sends 5-level voltages (PAM-5) on 4 twisted pairs at once, and Wi-Fi splits the frequency finely with OFDM and uses QAM (a combination of amplitude and phase) on each.
- The comparison of encoding schemes is in NRZ family and Manchester.
Multiplexing
Ways for several signals to share one link.
- FDM: split by frequency. Wi-Fi channels, radio stations.
- TDM: split by time. PON upstream, the old telephone network.
- WDM: send dozens of lights with different wavelengths (colors) together on one strand of fiber. This is why submarine cables have such large capacity. Details are in WDM.
Full duplex, half duplex, simplex
| Method | Meaning | Examples |
|---|---|---|
| Simplex | One direction only | Broadcasting |
| Half duplex | Both directions, but only one side at a time | Walkie-talkies, one Wi-Fi channel, hub Ethernet |
| Full duplex | Both sides at the same time | Telephone, switched Ethernet, two fiber strands |
Wi-Fi is half duplex because only one device can talk on a channel at a time. That is why the CSMA/CA above is needed. My notes are in transmission direction.
Bandwidth, throughput, latency
| Concept | Meaning | Unit | Analogy |
|---|---|---|---|
| Bandwidth | Theoretical maximum transfer rate | bps | Number of lanes |
| Throughput | Transfer rate actually achieved | bps | Number of cars that actually passed |
| Latency | Time from departure to arrival | ms | Travel time |
| Jitter | How uneven the arrival intervals are | ms | Buses arriving at uneven intervals |
| Packet loss | Share of what was sent that never arrived | % | Parcels that vanished on the way |
Throughput is lower than bandwidth. Congestion, control information such as headers, loss and retransmission, device performance and processing speed at both ends all cut into it. The theoretical maximum a link can reach is set by bandwidth and signal-to-noise ratio (Channel Capacity). Video downloads care about throughput, while video calls and games care about latency, jitter and loss.
Physical layer devices
A repeater only amplifies the signal at the physical layer, a switch opens up to the MAC at the link layer, and a router opens up to the IP at the network layer. Only hosts use all four layers.
- Repeater: re-amplifies a weakened signal to send it farther. It looks at neither content nor destination. The optical repeaters placed along submarine cables do the same job.
- Hub: a repeater with many ports. It sends a signal that comes in on one port out of every port, unchanged. So devices tied to a hub share one collision domain. Hubs have all been replaced by switches now.
- Modem and ONT: convert the Ethernet signal inside the home into the signal of the carrier's line (phone line, coax, fiber).
What the physical layer cannot do alone
- Where something starts and ends: bits just keep coming. Frame boundaries are set by the link layer with the preamble and length.
- Whose it is: there is no address. A hub sprays to everyone. Filtering is done by the link layer (the NIC's MAC check, switches).
- Fix errors: it does not know when noise flips a bit. The link layer's FCS finds it, and an upper layer resends.
9. To the other side of the world: the real structure of the internet
The internet is not one network but a network of networks. No single company owns it all. Tens of thousands of organizations each run their own part and connect to one another. The common rules used at those seams are IP and BGP.
This shows one possible path. The box color is the highest layer that device works at. Distances are rough estimates, not a measured path.
Access network
The first stretch that connects a user's device to the ISP. The lecture slides divide the path into user-side network → access network → ISP network → backbone → server network.
- Home: laptop → Wi-Fi → home router → Ethernet → ONT → optical fiber → the OLT at the carrier's central office. Several homes share one fiber strand through an optical splitter (PON).
- Phone: base station → the carrier's mobile core network. The core network holds the CGNAT and the gateway out to the internet.
- The public IP 203.0.113.5 is the address the ISP gave to the home router's WAN side. The home router ↔ ISP hop is also covered in Router ↔ ISP.
ISP, AS, IXP
- ISP (Internet Service Provider): a business that sells internet access. Each ISP is usually one or more ASes.
- Three ways ISPs connect to each other:
- Private peering: two providers plug a line directly into each other.
- Transit: pay an upstream provider to buy "a path to the whole internet".
- IXP (Internet Exchange Point): many providers gather at a large Ethernet switch in one building, set up BGP sessions with each other and exchange traffic. The IXP itself is link layer equipment (a switch fabric), and path decisions are made by each provider's routers with BGP.
- Tier 1: top-level providers that can reach every part of the internet without paying (through peering with each other alone). Providers below them buy transit from Tier 1 or from providers below Tier 1.
- Which providers a packet passes through is decided by each AS's BGP policy. It may not be the geographically shortest path.
Backbone and submarine cables
- Backbone: high-capacity core links connecting regions, countries and continents. Made of optical links of hundreds of Gbps to Tbps and large routers.
- Submarine cables: most international traffic between continents goes over optical cables under the sea. Satellites carry only a part.
- A cable holds a few fiber pairs, and each strand carries dozens of wavelengths with WDM.
- Every few tens of km on the sea floor there is an optical repeater that amplifies the weakened light. It is a physical layer device. Power is sent from land through a copper conductor inside the cable.
- Where a cable reaches land is a landing station, and from there it connects to land backbones and routers.
- Routes differ by region, and new cables get laid or old ones replaced. You can see a map at submarinecablemap.com.
- Seoul to São Paulo is about 18,000 km by great-circle distance (estimate, not measured). There is no direct cable, so traffic usually crosses the Pacific through the US or goes around via other continents.
Data centers, load balancers, CDN
- Servers sit in data centers. Incoming packets go through the data center router → firewall → load balancer to one of many servers. An L4 load balancer looks only at IP and port, and an L7 load balancer terminates TLS and looks at the HTTP path too.
- The cloud is not an abstract space either. It is the real computers in data centers like these. Clusters (computers in one place acting as one) and grids (connecting resources of many institutions) also end up exchanging messages over this network.
- CDN (Content Delivery Network): copies images, video and files to servers near the user (the edge) and serves them from there. DNS returns a nearby edge IP (region-based answers), or the same IP is advertised from many places (anycast), to send users to a nearby one. "Nearby" means by network path, load and policy, not geography.
- The chat message itself cannot be put on a CDN. It is data created in real time. But attachments such as a photo the friend sent can be fetched from a CDN. Video streaming uses CDN + adaptive quality selection together.
To the friend's phone: once more from the server
- The chat server unwraps the received "Hi" through TLS and WebSocket, reads it, and finds the recipient's connection.
- It builds a new message and sends it over the TCP connection the friend's phone keeps open. This is a new encapsulation. The packet from the laptop does not go on as is.
- The destination IP is 192.0.2.77, the public address of the friend's carrier NAT, and the port is the number that NAT assigned to the friend's phone connection. The friend's phone opened the connection first, so there is an entry in the CGNAT translation table.
- US → Brazil (land fiber, submarine cable, Brazilian ISP) → carrier core network → CGNAT turns the destination back into 100.64.12.34 → base station.
- The base station assigns radio resources to the friend's phone and sends the frame. The phone's NIC (modem) → driver → kernel TCP/IP → socket → chat app. The app shows "Hi" on the screen.
Where delay comes from
Four kinds add up at every hop.
| Delay | Cause | What sets its size |
|---|---|---|
| Processing delay | Header checks, FCS and checksums, table lookups | Device performance (µs per router) |
| Queuing delay | Waiting in the buffer until earlier packets leave | Traffic at that moment. Different every time |
| Transmission delay | Time to push all the frame's bits onto the link | Frame length ÷ link speed |
| Propagation delay | Time for the signal to travel along the medium | Distance ÷ signal speed |
- Propagation delay cannot be reduced by upgrades. Light in fiber travels at about 2/3 of its speed in a vacuum, about 200,000 km per second. A path of about 20,000 km takes about 100 ms one way (calculated, not measured). So the RTT to the other side of the world has a floor of several hundred ms, and the only way to lower that floor is to put servers closer (CDN, regional servers).
- Transmission delay shrinks as the link gets faster. A 1500 B frame takes 12 µs on a 1 Gbps link and 1.2 ms on 10 Mbps (calculated).
- Queuing delay differs per packet, which creates jitter, and when the queue overflows it becomes loss. This is exactly the signal TCP congestion control watches.
- On top of this comes processing at both ends (waiting for the server's response, app processing, TCP and TLS handshake round trips). On a first connection, TCP 1 RTT + TLS 1 RTT pass before the first message goes out, so to the other side of the world that alone adds several hundred ms. This is why a chat app that keeps its connection open feels fast.
- A packet-switched network shares links among many users. Even to the same server, delay and throughput vary from moment to moment. The comparison with circuit switching is in Packet Switching.
10. Everything that crosses layers, at once
Encapsulation and decapsulation
| Layer | What the sender adds | In this example | What the receiver checks |
|---|---|---|---|
| Application | Message, TLS record | Chat JSON → WebSocket → TLS | Decryption, parsing the message |
| Transport | Source and destination ports, seq, ack, window, checksum | 51000 → 443 | Find the socket by 5-tuple, reorder, ACK |
| Network | Source and destination IP, TTL, protocol number, header checksum | 192.168.0.20 → 198.51.100.10, TTL 64, 6 | Whether the destination IP is mine, protocol number |
| Link | Source and destination MAC, EtherType, FCS | Laptop MAC → home router MAC, 0x0800 | Whether the destination MAC is mine, FCS |
| Physical | Preamble, encoded signal | Wi-Fi radio | Signal → bits, clock sync |
How far each device opens
| Device | Layers it opens | What it does |
|---|---|---|
| Repeater, hub, optical repeater | Physical | Re-amplify the signal or copy it to everyone |
| Switch, bridge, AP | Link | Pick a port by MAC, convert wireless ↔ wired frames |
| Router | Network | Next hop by IP, TTL − 1, new frame |
| NAT router, firewall | Network + transport | Rewrite and inspect IPs and ports |
| L7 load balancer, proxy | Up to application | Terminate TLS, look at HTTP and pick a server |
| Host (laptop, server) | All | Encapsulation and decapsulation |
What changes on each link vs what stays
| Header | Changes on each link | Stays the same end to end |
|---|---|---|
| Link | Source and destination MAC, frame type (Wi-Fi ↔ Ethernet) | |
| IP | TTL (−1 per hop), header checksum, source IP at NAT | Destination IP (when there is no NAT on the server side) |
| TCP | Source port at NAT | Destination port 443, seq, data |
| Application | Content encrypted with TLS (the middle cannot read it) |
The same table for a web request is in What changes on each link vs what stays.
Protocols that tie layers together
| Protocol | Its own layer | Carried in | What it connects |
|---|---|---|---|
| DNS | Application | UDP/TCP 53 | Application names → network IPs |
| DHCP | Application | UDP 67/68 | Network layer settings (IP, mask, gateway, DNS) |
| ARP | Between link and network | Directly in Ethernet frames | Network IP → link MAC |
| NAT | A function of network devices | Rewrites IP and TCP/UDP headers | Private address ↔ public address (including ports) |
| ICMP | Network | IP (protocol 1) | Reports errors during IP delivery to the source, ping and traceroute |
| BGP | Behaves like an application | TCP 179 | Route information between ASes → network layer routing tables |
| OSPF | Network layer control | IP (protocol 89) | Link costs inside an AS → routing tables |
| TLS | Application (OSI 5 to 6) | TCP | Encryption and authentication of application data |
A VPN wraps this table once more. It encrypts the entire IP packet and puts it inside UDP, so you get a network layer stacked on top of another network layer. The process is in When using a VPN.
11. Numbers table
As of 2026-11-25. Only values set by specifications and calculated values are included. Nothing here was measured.
| Item | Value | Source or basis |
|---|---|---|
| IPv4 address / IPv6 address / MAC address | 32 / 128 / 48 bits | Spec |
| Port number | 16 bits (0 to 65535) | Spec |
| TCP / UDP / IPv4 / IPv6 header | 20+ / 8 / 20+ / 40 B | Spec (+ = grows with options) |
| Ethernet header + FCS | 14 + 4 B (preamble 8 B extra) | Spec |
| Ethernet MTU / typical TCP MSS | 1500 / 1460 B | 1500 − 20 − 20 |
| Default TTL | Linux and macOS 64, Windows 128 | OS default settings |
| Speed of light in fiber | About 200,000 km/s | Speed of light in vacuum ÷ refractive index of about 1.5 |
| Seoul ↔ São Paulo great-circle distance | About 18,000 km | Estimate |
| One-way propagation delay over a 20,000 km path | About 100 ms | Calculated |
| Sending 1500 B at 1 Gbps / 10 Mbps | 12 µs / 1.2 ms | Calculated (12,000 bits ÷ link speed) |