TCP/IP Suite
“TCP/IP is the actual implementation that runs the Internet — the OSI model is just the theory.”
Overview
The TCP/IP (Transmission Control Protocol/Internet Protocol) Suite is the practical set of protocols that powers the Internet. Unlike the theoretical OSI model with 7 layers, TCP/IP has 4 layers (sometimes described as 5) and was developed by DARPA in the 1970s before OSI even existed.
TCP/IP vs OSI Model
graph LR
subgraph "OSI Model (7 Layers)"
OSI7[Application]
OSI6[Presentation]
OSI5[Session]
OSI4[Transport]
OSI3[Network]
OSI2[Data Link]
OSI1[Physical]
end
subgraph "TCP/IP Model (4 Layers)"
TCP4[Application]
TCP3[Transport]
TCP2[Internet]
TCP1[Network Access]
end
OSI7 -.-> TCP4
OSI6 -.-> TCP4
OSI5 -.-> TCP4
OSI4 -.-> TCP3
OSI3 -.-> TCP2
OSI2 -.-> TCP1
OSI1 -.-> TCP1
| TCP/IP Layer | OSI Equivalent | Protocols | PDU |
|---|---|---|---|
| Application | L5+L6+L7 | HTTP, DNS, SMTP, FTP, SSH | Data |
| Transport | L4 | TCP, UDP | Segment/Datagram |
| Internet | L3 | IP, ICMP, ARP, RARP | Packet |
| Network Access | L1+L2 | Ethernet, Wi-Fi | Frame |
The TCP/IP Protocol Stack
graph TD
subgraph "Application Layer"
HTTP["HTTP/HTTPS"]
DNS["DNS"]
SMTP["SMTP/IMAP"]
FTP["FTP/SFTP"]
SSH["SSH"]
DHCP["DHCP"]
SNMP["SNMP"]
end
subgraph "Transport Layer"
TCP["TCP<br/>Reliable, ordered"]
UDP["UDP<br/>Fast, best-effort"]
end
subgraph "Internet Layer"
IP["IPv4/IPv6"]
ICMP["ICMP"]
ARP["ARP"]
RARP["RARP"]
end
subgraph "Network Access Layer"
ETH["Ethernet"]
WIFI["Wi-Fi"]
FIBER["Fiber"]
end
HTTP --> TCP
DNS --> UDP
DNS --> TCP
SMTP --> TCP
SSH --> TCP
DHCP --> UDP
SNMP --> UDP
TCP --> IP
UDP --> IP
ICMP --> IP
IP --> ETH
IP --> WIFI
ARP --> ETH
Key Protocols Summary
Internet Layer Protocols
| Protocol | Function | Details |
|---|---|---|
| IP | Logical addressing, routing | Connectionless, best-effort delivery |
| ICMP | Error reporting, diagnostics | ping, traceroute |
| ARP | IP → MAC resolution | Broadcasts on local network |
| RARP | MAC → IP resolution | Obsolete, replaced by DHCP |
| IGMP | Multicast group management | Join/leave multicast groups |
Transport Layer Protocols
| Protocol | Function | Key Features |
|---|---|---|
| TCP | Reliable delivery | 3-way handshake, flow/congestion control |
| UDP | Fast delivery | No connection, minimal overhead |
| SCTP | Multi-streaming | Message-oriented, multi-homing |
How Data Flows Through TCP/IP
sequenceDiagram
participant App as Application<br/>(HTTP GET)
participant TCP as Transport<br/>(TCP)
participant IP as Internet<br/>(IP)
participant Net as Network Access<br/>(Ethernet)
participant Wire as Physical Medium
App->>TCP: HTTP Request (Data)
TCP->>TCP: Add TCP header (src/dest port)
TCP->>IP: TCP Segment
IP->>IP: Add IP header (src/dest IP)
IP->>Net: IP Packet
Net->>Net: Add Ethernet header + trailer
Net->>Wire: Ethernet Frame → Bits
Note over Wire: Crosses network (routers, switches)
Wire->>Net: Bits → Frame
Net->>Net: Remove Ethernet header
Net->>IP: IP Packet
IP->>IP: Remove IP header
IP->>TCP: TCP Segment
TCP->>TCP: Remove TCP header
TCP->>App: HTTP Request (Data)
Addressing at Each Layer
| Layer | Address Type | Size | Scope | Example |
|---|---|---|---|---|
| Application | URL/Domain | Variable | Global | www.example.com |
| Transport | Port Number | 16 bits | Host | :443 (HTTPS) |
| Internet | IP Address | 32/128 bits | Global | 93.184.216.34 |
| Network Access | MAC Address | 48 bits | Local | 00:1A:2B:3C:4D:5E |
Interview Questions
Beginner
Q1: What is the TCP/IP model? The TCP/IP model is a 4-layer networking framework: Application, Transport, Internet, and Network Access. It’s the practical implementation used on the Internet, developed before the OSI model. Each layer has specific protocols and responsibilities, and data is encapsulated with headers as it moves down the stack.
Q2: How does TCP/IP differ from OSI? OSI has 7 layers and is theoretical; TCP/IP has 4 layers and is practical. TCP/IP merges OSI’s top three layers (Application, Presentation, Session) into one Application layer, and merges the bottom two (Data Link, Physical) into Network Access. TCP/IP was developed first (1970s); OSI came later (1984) as a standardization effort.
Q3: Why does the Internet use TCP/IP instead of OSI? TCP/IP was developed first and had working implementations (ARPANET). By the time OSI was standardized, TCP/IP was already dominant. TCP/IP’s simpler 4-layer model was easier to implement. The “OSI won the battle of the models, TCP/IP won the war of implementations.”
Intermediate
Q4: Explain the encapsulation process in TCP/IP. As data moves down the TCP/IP stack:
- Application: Creates the data (e.g., HTTP request)
- Transport: Adds TCP/UDP header (source/dest ports) → Segment/Datagram
- Internet: Adds IP header (source/dest IP) → Packet
- Network Access: Adds frame header (MAC addresses) and trailer (CRC) → Frame At the receiving end, each layer strips its header and passes data up.
Q5: What happens when you type google.com in a browser? Complete TCP/IP flow:
- DNS (Application/UDP): Resolve google.com → IP address
- TCP (Transport): 3-way handshake with server (SYN, SYN-ACK, ACK)
- TLS (Application): Negotiate encryption (if HTTPS)
- HTTP (Application): Send GET request, receive HTML
- TCP/IP: Segments → Packets → Frames → Bits across the Internet
- Browser: Render HTML, fetch CSS/JS (repeat steps 2-5)
Q6: Why is IP called “best-effort” delivery? IP provides no guarantees:
- No delivery guarantee: Packets can be dropped
- No ordering guarantee: Packets can arrive out of order
- No duplicate protection: Same packet can arrive multiple times
- No error correction: Only header checksum, no retransmission Reliability is left to TCP (or the application). This design keeps IP simple and fast.
Advanced / FAANG-Level
Q7: Design a network architecture for a global SaaS application. Architecture:
- Edge layer: CDN (Cloudflare/CloudFront) for static content, DDoS protection
- DNS: GeoDNS with health checks for global load balancing
- Load balancing: L4 (NLB) for TCP/UDP, L7 (ALB) for HTTP routing
- Application: Microservices in Kubernetes, multi-region deployment
- Transport: TCP for reliability, HTTP/2 for multiplexing, gRPC for inter-service
- Database: Multi-region replication, read replicas per region
- Security: TLS everywhere, WAF at edge, zero-trust networking
- Monitoring: Distributed tracing (Jaeger), metrics (Prometheus), logging (ELK)
Q8: How would you debug a “connection refused” error across the TCP/IP stack? Systematic debugging:
- Network Access: Is the interface up? (
ip link,ifconfig) - Internet: Can you reach the host? (
ping, check IP/routing withip route) - Transport: Is the port open? (
telnet host port,nmap -p port host) - Application: Is the service running? (
systemctl status, check logs) - Firewall: Is traffic blocked? (
iptables -L,ufw status) Common causes: service not running, wrong port, firewall rule, binding to localhost only
Q9: Explain how the TCP/IP stack handles a packet traversing the Internet. At each hop:
- Host A (sender): Application → TCP segment → IP packet → Ethernet frame → bits on wire
- Switch: Reads MAC address, forwards frame to correct port (L2)
- Router: Strips frame, reads IP destination, decrements TTL, looks up routing table, creates new frame for next hop (L3)
- Multiple routers: Each router does step 3 — IP addresses stay constant, MAC addresses change per hop
- Switch (near destination): Forwards to destination MAC
- Host B (receiver): Bits → frame → packet → segment → data → application
Key insight: IP addresses are end-to-end, MAC addresses are hop-by-hop.
Common Mistakes
- ❌ Thinking TCP/IP is just TCP and IP — it’s the entire protocol suite
- ❌ Confusing the TCP/IP model with the OSI model — they have different numbers of layers
- ❌ Forgetting that IP is unreliable — TCP adds reliability on top
- ❌ Mixing up encapsulation order — data goes App → Transport → Internet → Network Access
- ❌ Assuming the Internet uses OSI protocols — it uses TCP/IP
Summary
- TCP/IP is the practical protocol suite that powers the Internet
- 4 layers: Application, Transport, Internet, Network Access
- Encapsulation: Each layer adds its header as data moves down
- IP: Logical addressing and routing (best-effort)
- TCP: Reliable delivery with flow/congestion control
- UDP: Fast, minimal-overhead delivery
- Understanding TCP/IP is essential for debugging, system design, and interviews
Cross-References
- OSI Model — Theoretical framework
- IP Protocol — Internet Layer details
- TCP Protocol — Transport Layer deep dive
- UDP Protocol — UDP details
- DNS — Application Layer resolution