Networking Models — OSI & TCP/IP, Application Layer
768 words
4 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Networking Models — OSI & TCP/IP, Application Layer ## 🎯 Learning Objectives - Compare OSI (7-layer) and TCP/IP (5-layer) models - Explain the role of each layer - Trace HTTP request/response flow, DNS resolution, SMTP mail delivery - Analyze protocol headers * * * ## 1. Network Models ### 1.1 Intuition Networkin...

Networking Models — OSI & TCP/IP, Application Layer
🎯 Learning Objectives
- Compare OSI (7-layer) and TCP/IP (5-layer) models
- Explain the role of each layer
- Trace HTTP request/response flow, DNS resolution, SMTP mail delivery
- Analyze protocol headers
1. Network Models
1.1 Intuition
Networking is complex — layers break it into manageable pieces. Each layer provides services to the layer above and receives services from the layer below. Like a government hierarchy: the president (Application) doesn't worry about carrier pigeons (Physical).
1.2 OSI vs TCP/IP
(Diagram)
| OSI Layer | TCP/IP Layer | Protocol Data Unit (PDU) | Example Protocols |
|---|---|---|---|
| Application | Application | Message | HTTP, DNS, SMTP, FTP |
| Presentation | (merged into Application) | — | TLS/SSL |
| Session | (merged into Application) | — | SOCKS |
| Transport | Transport | Segment (TCP) / Datagram (UDP) | TCP, UDP |
| Network | Network/Internet | Packet | IP, ICMP, ARP, OSPF |
| Data Link | Data Link | Frame | Ethernet, WiFi |
| Physical | Physical | Bit | 1000BASE-T, 802.11 |
1.3 Encapsulation
(Diagram)
Each layer adds its own header (and sometimes trailer) around the data from the layer above.
2. Application Layer Protocols
2.1 HTTP (HyperText Transfer Protocol)
(Diagram)
HTTP Methods:
| Method | Purpose | Safe? | Idempotent? |
|---|---|---|---|
| GET | Retrieve resource | Yes | Yes |
| HEAD | Get headers only | Yes | Yes |
| POST | Submit data | No | No |
| PUT | Replace resource | No | Yes |
| DELETE | Remove resource | No | Yes |
| PATCH | Partial update | No | No |
2.2 DNS (Domain Name System)
(Diagram)
DNS Record Types:
| Type | Description | Example |
|---|---|---|
| A | IPv4 address | example.com → 93.184.216.34 |
| AAAA | IPv6 address | example.com → 2606:2800:220:1:248:1893:25c8:1946 |
| CNAME | Canonical name (alias) | www.example.com → example.com |
| MX | Mail exchange | @ → mail.example.com (priority 10) |
| NS | Name server | example.com → ns1.example.com |
| TXT | Text record (verification) | SPF, DKIM keys |
2.3 SMTP (Simple Mail Transfer Protocol)
(Diagram)
2.4 FTP (File Transfer Protocol)
- Control connection: Port 21 (commands)
- Data connection: Port 20 (data)
- Active mode: Server connects back to client for data
- Passive mode: Client connects to server for data
3. Transport Layer: UDP
3.1 UDP Header
pseudo0 7 8 15 16 23 24 31 +--------+--------+--------+--------+ | Source Port | Destination | | | Port | +--------+--------+--------+--------+ | Length | Checksum | +--------+--------+--------+--------+ | Data (payload) | +------------------------------------+
3.2 UDP Properties
| Property | Description |
|---|---|
| Connectionless | No handshake, just send |
| Unreliable | No retransmission, no ordering |
| Low overhead | 8-byte header |
| No flow control | Sender can overwhelm receiver |
| No congestion control | Can send at any rate |
Used by: DNS, DHCP, VoIP, streaming, SNMP, QUIC (HTTP/3)
4. Common Pitfalls
Pitfall 1: Confusing OSI layers
Mistake: "TCP is a network layer protocol."
Correction: TCP is transport layer (Layer 4). IP is network layer (Layer 3). Remember: TCP segments, IP packets, Ethernet frames.
Pitfall 2: DNS uses UDP AND TCP
Fact: DNS uses UDP for standard queries (≤ 512 bytes), but switches to TCP for zone transfers and large responses (DNSSEC, > 512 bytes).
Pitfall 3: HTTP is stateless
Correction: HTTP is stateless by design, but cookies, sessions, and tokens add state on top of HTTP.
5. 📐 Key Formulas / Concepts
| Concept | Description |
|---|---|
| Encapsulation | Each layer adds a header to the data |
| PDU | Layer-specific data unit (segment, packet, frame) |
| Port numbers | Identify application (0-65535) |
| Well-known ports | HTTP(80), HTTPS(443), DNS(53), SMTP(25), FTP(21) |
6. 📝 Practice Questions
Q1: What is the difference between a TCP segment and an IP packet?Answer: A TCP segment is the transport layer PDU — it contains a TCP header and application data. An IP packet is the network layer PDU — it contains an IP header, and its payload is typically a TCP segment or UDP datagram. The IP packet is encapsulated inside an Ethernet frame at the data link layer. Q2: Why does DNS use UDP for most queries?Answer: DNS queries are typically small (one request, one response). UDP avoids the overhead of TCP's connection establishment (3-way handshake). If the response exceeds 512 bytes (or EDNS0 limit), DNS falls back to TCP. Q3: Trace the layers involved when you type http://example.com in a browser.Answer:
- Application: HTTP GET request formed
- Transport: TCP connection established to 93.184.216.34:80
- Network: IP packets routed through the internet
- Data Link: Ethernet frames on local network
- Physical: Electrical/optical signals
Before this, DNS (Application/UDP) resolved the domain. Q4: What is the difference between HTTP and HTTPS?Answer: HTTPS is HTTP over TLS/SSL. TLS provides encryption, authentication (server certificate), and integrity checking. HTTPS uses port 443 instead of 80. Q5: List three protocols at each layer of the TCP/IP model.Answer:
- Application: HTTP, DNS, SMTP, FTP, SSH
- Transport: TCP, UDP, QUIC
- Network: IP (v4/v6), ICMP, OSPF, ARP (sometimes in Network)
- Data Link: Ethernet, WiFi (802.11), PPP
7. 🔗 Cross-References
- Week 2 - Transport Layer: TCP in detail
- Week 3 - Network Layer: IP addressing, routing
- Week 4 - Data Link: Ethernet, MAC
- BSCS4003 (Privacy & Security): TLS/SSL, HTTPS Join Discord NextTCP & UDP