🌍

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

Sending
Application Transport Internet Network
Physical
Transmission
Receiving
Network Internet Transport Application
📦

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.

Frame Header IP Header TCP Header HTTP Data

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 PC
Router
ISP
Your ISP
☁️
Internet
Data Center
Server
Step 1: Application Creates Data

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

192 . 168 . 1 . 100
4 octets (8 bits each) = 32 bits total = ~4.3 billion addresses

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
Localhost
Loopback - refers to your own machine
0.0.0.0
All interfaces
Listen on all network interfaces
255.255.255.255
Broadcast
Send to all devices on network
8.8.8.8
Google DNS
Public DNS resolver
🔄

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 Transmission Control Protocol
Reliable delivery
Ordered delivery
Connection: Connection-oriented
Speed: Slower
Common Uses:
HTTP/HTTPSEmail (SMTP)File transfers (FTP)SSH
UDP User Datagram Protocol
May lose packets
No ordering
Connection: Connectionless
Speed: Faster
Common Uses:
Video streamingOnline gamingVoIPDNS queries

TCP 3-Way Handshake

Client
1. SYN
2. SYN-ACK
3. ACK
Server

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

Click on a device to learn more

Typical Home Network

📱💻🖥️
Devices
📡
Router
📶
Modem
ISP
Internet

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:

OSI Layer 7,6,5 TCP/IP Application
OSI Layer 4 TCP/IP Transport
OSI Layer 3 TCP/IP Internet
OSI Layer 2,1 TCP/IP Network Access

Key Terms to Remember

Master these terms for technical interviews