The TCP/IP Model: The Real Internet
While OSI is the “map”, TCP/IP is the actual “territory”. It condenses the 7 layers of OSI into 4 practical layers that correspond to real-world protocols.
1. OSI vs TCP/IP Mapping
| OSI Layer | TCP/IP Layer | Protocols |
|---|---|---|
| Application (7), Presentation (6), Session (5) | Application | HTTP, DNS, SSH, TLS |
| Transport (4) | Transport | TCP, UDP |
| Network (3) | Internet | IP, ICMP, ARP |
| Data Link (2), Physical (1) | Network Access | Ethernet, Wi-Fi |
[!NOTE] Why did TCP/IP win? OSI was designed by committees (ISO). TCP/IP was built by engineers (DARPA) who prioritized “rough consensus and running code.” TCP/IP is looser but works.
2. The Hourglass Model
The internet is often described as an “hourglass”.
- Top (Application): Many protocols (HTTP, SMTP, FTP).
- Middle (Internet): Only ONE protocol: IP (Internet Protocol).
- Bottom (Network Access): Many mediums (Copper, Fiber, Radio).
Everything must run over IP. This constraint allowed the internet to scale.
3. Interactive: The Packet Journey
Follow a packet from your Laptop to a Server.
4. Code Example: The Leaky Abstraction
In theory, you shouldn’t care about IP addresses when writing an App. In practice, you do. Here is how you access the TCP/IP stack in Go.
package main
import (
"fmt"
"net"
)
func main() {
// 1. Resolve DNS (Application Layer) -> IP (Internet Layer)
ips, _ := net.LookupIP("google.com")
fmt.Printf("IP Layer: %v\n", ips[0])
// 2. Dial TCP (Transport Layer)
// The OS picks a random source port for us
conn, _ := net.Dial("tcp", "google.com:80")
// 3. Send Data (Application Layer)
// We just write bytes. The OS handles ACKs, Retries, and Windowing.
fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
}