How the Internet Works
TCP/IP stack, packets, routing, and network fundamentals
What is the Internet?
A network of networks
The Internet is a global network of interconnected computer networks that communicate using standardized protocols. It's not controlled by any single organization - it's a decentralized system where thousands of networks voluntarily interconnect.
When you send data over the internet, it's broken into small packets that travel independently through multiple networks, potentially taking different routes, before being reassembled at the destination.
The TCP/IP Model
The layered architecture of internet communication
Four Layers of TCP/IP
Each layer has a specific responsibility and communicates with adjacent layers
Transmission
Encapsulation
As data moves down the stack, each layer adds its own header (and sometimes trailer). This is called encapsulation. On the receiving end, each layer removes its header - this is decapsulation.
Journey of a Packet
How data travels across the internet
From Your Computer to a Server
Follow a packet as it hops through the network
Your browser creates an HTTP request to fetch a webpage
Hop Count
Each router a packet passes through is called a "hop". A typical request
might go through 10-20 hops.
Use traceroute to see the path.
Round-Trip Time (RTT)
Time for a packet to go and return. Same city: ~5-20ms. Cross-continent: ~100-200ms. Speed of light is the physical limit.
IP Addressing
How devices are identified on the network
IPv4 Address Format
Private IP Ranges (RFC 1918)
These addresses are not routable on the public internet. Used for internal networks.
10.0.0.0/8 Large private networks 172.16.0.0/12 Medium private networks 192.168.0.0/16 Home/small office (most common) Special Addresses
127.0.0.1 0.0.0.0 255.255.255.255 8.8.8.8 NAT (Network Address Translation)
Your router uses NAT to share one public IP among all your devices. Devices get private IPs (like 192.168.1.x), and the router translates between private and public addresses. This is why IPv4 hasn't run out yet - but IPv6 eliminates the need for NAT.
Common Interview Question
"What happens when you type a URL?"
Part of the answer involves IP addressing: your device needs to resolve the domain to an IP (DNS),
then packets are addressed with source IP (your public IP via NAT) and destination IP (server's IP).
TCP vs UDP
Two transport protocols with different trade-offs
TCP 3-Way Handshake
This happens before any data is sent. UDP skips this entirely.
| Feature | TCP | UDP |
|---|---|---|
| Reliability | Guaranteed delivery | Best effort (may lose packets) |
| Ordering | Packets arrive in order | No ordering guarantee |
| Connection | 3-way handshake first | Just send data |
| Error checking | Checksums + retransmission | Checksums only |
| Flow control | Yes (prevents overwhelming receiver) | No |
| Congestion control | Yes (adjusts to network) | No |
Use TCP when:
- • Data must arrive complete and correct
- • Order matters (loading a webpage)
- • You can tolerate some latency
Use UDP when:
- • Speed is critical (real-time apps)
- • Some packet loss is acceptable
- • You handle reliability yourself
Network Devices
The hardware that makes the internet work
Typical Home Network
Most home "routers" are actually a router + switch + wireless access point + modem combined
OSI vs TCP/IP Model
You might see references to 7 OSI layers vs 4 TCP/IP layers. OSI is a theoretical model; TCP/IP is what the internet actually uses. Key mapping:
Key Terms to Remember
Master these terms for technical interviews