Lesson 1 of 9 · 20m
The Layered Internet: IP, TCP, UDP, and What Each Layer Promises
A practical model of the TCP/IP stack: what IP does not guarantee, what TCP adds, what UDP deliberately leaves out, and why layer boundaries matter when systems fail.
The first mistake new operators make is treating “the network” as one thing. It is a stack of narrow contracts. IP moves datagrams between hosts with no promise of delivery, order, or duplication control. TCP builds a reliable byte stream on top of that uncertain service. UDP exposes the uncertainty almost directly. If you keep those contracts separate, most packet captures stop looking like noise.
IP is a courier, not a conversation
IPv4 and IPv6 packets contain source and destination addresses, a hop limit or TTL, protocol number, and payload. Routers forward them independently. There is no connection state in IP itself and no requirement that two packets take the same path.
10.12.4.18:51842 -> 203.0.113.20:443 TCP segment, seq 1001, len 1460
10.12.4.18:51842 -> 203.0.113.20:443 TCP segment, seq 2461, len 1460
203.0.113.20:443 -> 10.12.4.18:51842 TCP ACK 3921Two segments can arrive out of order because one path congested, a route changed, or a middlebox sprayed packets across links. IP is allowed to do that. TCP is expected to cope.
TCP is a byte stream, not a message service
Applications write bytes; TCP decides how to segment them. A single write() can be split across packets, and several small writes can be coalesced into one segment. This is why protocols over TCP need framing: length prefixes, delimiters, or explicit headers.
# Application framing belongs above TCP.
payload = b"hello"
frame = len(payload).to_bytes(4, "big") + payload
sock.sendall(frame)If your application reads exactly 5 bytes and calls that a message, it will appear to work in testing and corrupt production traffic under packetization changes.
UDP is a decision, not a shortcut
UDP preserves datagram boundaries and adds ports plus a checksum. It does not retransmit, reorder, pace, or acknowledge. That is useful for DNS, RTP, game state, and QUIC because the application either does not need reliability or wants to implement a better reliability policy itself.
Encapsulation is the debugging map
Ethernet | IPv6 | TCP | TLS | HTTP/2 | application protocolWhen something breaks, ask which contract failed. Ethernet counters show physical or driver trouble. IP shows reachability. TCP shows loss, reordering, and window pressure. TLS shows authentication or record errors. HTTP shows application semantics. Do not debug layer seven with layer three tools or the reverse.
Field notes
- TCP sequence numbers count bytes, not packets.
netstatorssoutput shows sockets, not proof that packets are flowing.- ICMP is not “the network being noisy”; it is often the control message explaining why forwarding failed.
- NAT and firewalls track flow state, but IP itself does not.
- Most “TCP fragmentation” conversations are really about IP fragmentation or TCP segmentation; learn the difference early.
Was this lesson helpful?