TCP/IP
Underneath HTTP and almost everything else sits TCP/IP — the pair of protocols that move bytes across the internet without losing them.
The internet is a packet-switched network: data is chopped into small packets, each routed independently, and reassembled at the far end. Two protocols do most of the work — IP handles addressing and routing, TCP handles reliability.
IP: addressing
Every device has an IP address. IPv4 looks like 192.168.1.10 (four bytes). IPv6 looks like 2001:db8::1 and exists because we ran out of IPv4 addresses. IP gets a packet toward a destination by hopping through routers, but it makes no promises — packets can arrive out of order, duplicated, or not at all.
TCP: reliability
TCP builds a dependable stream on top of unreliable IP. It:
- numbers every byte so the other side can reorder them,
- acknowledges what it received, and retransmits what went missing,
- uses flow control and congestion control so it does not overwhelm the receiver or the network.
The three-way handshake
Before any data flows, TCP sets up a connection:
Client --- SYN ---> Server
Client <-- SYN/ACK -- Server
Client --- ACK ---> Server
(connection open)
This is why a brand-new connection has a little latency cost — a full round trip before the first byte of real data. (TLS then adds its own handshake on top; see the TLS tutorial.)
Ports
An IP address finds the machine; a port finds the program on it. Some well-known ports:
| Port | Service |
|---|---|
| 80 | HTTP |
| 443 | HTTPS |
| 22 | SSH |
| 53 | DNS |
TCP vs UDP
UDP is the no-promises alternative: fire a packet and hope. It has no handshake and no retransmission, which makes it fast and great for video calls, games, and DNS, where a slightly late packet is worse than a lost one. HTTP/3 actually runs over UDP (via QUIC) and rebuilds reliability itself.