TCP/IP Model
π TCP/IP Networking Model β Interview-Friendly Guide
The TCP/IP Model (Internet Protocol Suite) is the real-world standard for how data moves across networks.
It defines layers, each with a specific role, much like a postal system delivering packages.
This guide gives you:
- π Detailed Explanation of Each Layer
- π€ Interview Q&A (Interviewerβs POV)
- β‘ Cheat-Sheet for Quick Revision
π Overview of TCP/IP Model
- Developed by DARPA (ARPANET) β evolved into todayβs Internet Protocol Suite.
- Named after TCP (Transmission Control Protocol) & IP (Internet Protocol).
- Versions:
- Original: 4 Layers
- Modern learning version: 5 Layers (Physical β Data Link β Network β Transport β Application)
π¦ The Five Layers of TCP/IP
πΉ Layer 1: Physical Layer
Role: Moves raw bits (0s and 1s) over cables or radio waves.
- Standards: Ethernet (IEEE 802.3), Wi-Fi (IEEE 802.11)
- Examples: Connectors, cables, signals.
π€ Interview Q:
- Q: What does the Physical Layer define?
π A: How data (bits) is transmitted physically β cables, connectors, signals, and encoding.
πΉ Layer 2: Data Link Layer
Role: Ensures hop-to-hop delivery within a local network.
- Uses MAC addresses (like house numbers).
- Devices: Switches.
- Unit: Frame.
π€ Interview Qs:
- Q: Whatβs the difference between MAC and IP addresses?
π A: MAC = Physical hardware address (local). IP = Logical address (global, routable). - Q: Which device works at Layer 2?
π A: Switch.
πΉ Layer 3: Network Layer
Role: Handles end-to-end delivery across networks.
- Uses IP addresses (like postal codes).
- Devices: Routers.
- Unit: Packet.
π€ Interview Qs:
- Q: Whatβs the main job of the Network Layer?
π A: Routing packets using IP addresses from source to destination. - Q: Why doesnβt the destination IP change during transit?
π A: Because IP provides end-to-end delivery. Only MAC addresses change per hop.
πΉ Layer 4: Transport Layer
Role: Ensures application-to-application delivery.
- Uses port numbers (like flat numbers in a building).
- Two main protocols:
- TCP (reliable, connection-oriented, slow but accurate)
- UDP (fast, connectionless, best-effort)
- Unit: Segment.
π€ Interview Qs:
- Q: Difference between TCP and UDP?
π A: TCP is reliable, ordered, connection-based (used in HTTP, FTP).
UDP is fast, connectionless, no guarantee (used in VoIP, DNS). - Q: What is the TCP 3-way handshake?
π A: SYN β SYN-ACK β ACK. Used to establish a reliable TCP connection.
πΉ Layer 7: Application Layer
Role: Provides services for apps to communicate.
- Protocols: HTTP/HTTPS, DNS, FTP, SMTP, SSH.
- Not the applications themselves, but the languages they use to talk.
π€ Interview Qs:
- Q: Is HTTPS an application or protocol?
π A: Itβs a protocol at Layer 7, not the browser itself. - Q: Which layer does DNS belong to?
π A: Application Layer.
β‘ Where does HTTP really belong?
π HTTP at the Application Layer
HTTP (HyperText Transfer Protocol) is an Application Layer protocol.
- Defines how web clients (browsers) and servers exchange data (requests & responses).
Example: A browser sending
GET /index.htmlto a server.- Layer: Application (Layer 5 in TCP/IP, Layer 7 in OSI).
πΉ Why do people mention HTTP with TCP (Transport Layer)?
Because HTTP depends on TCP as its underlying transport service:
- HTTP runs on top of TCP (almost always over port 80 for HTTP, port 443 for HTTPS).
- TCP ensures reliable, ordered delivery of HTTP messages.
- So when we say βHTTP over TCPβ, weβre talking about layer stacking:
π¦ Example: Browser Loading a Webpage
- Application Layer (HTTP)
- Browser creates an HTTP request:
1
GET /index.html HTTP/1.1
- Browser creates an HTTP request:
- Transport Layer (TCP)
- Adds source port (random, e.g., 49152) and destination port (80 or 443).
- Handles 3-way handshake, reliability, retransmission.
- Network Layer (IP)
- Adds source & destination IP addresses.
- Data Link + Physical Layers
- Frames β Bits β Sent over cable/Wi-Fi.
π€ Interview Tip
Q: Which layer does HTTP belong to?
π Always answer: Application Layer.Q: What transport protocol does HTTP use?
π Answer: TCP (port 80/443).Q: Explain the relationship.
π HTTP = Layer 7, but it relies on TCP (Layer 4) for transport.
β Final Clarification
- HTTP = Application Layer
- TCP = Transport Layer
- They work together β HTTP rides on TCP.
π Encapsulation & De-Encapsulation
Encapsulation (Sender Side)
- App Layer: Data created (web request).
- Transport Layer: Adds port numbers β Segment.
- Network Layer: Adds IP addresses β Packet.
- Data Link Layer: Adds MAC + trailer β Frame.
- Physical Layer: Converts to bits.
De-Encapsulation (Receiver Side)
Bits β Frame β Packet β Segment β Data β Application.
π€ Interview Qs:
- Q: Whatβs encapsulation?
π A: Process of wrapping data with headers/trailers as it moves down the stack. - Q: Which layer adds trailers?
π A: Data Link Layer.
π OSI Model vs TCP/IP Model
| Feature | OSI Model | TCP/IP Model |
|---|---|---|
| Layers | 7 | 5 |
| Usage | Conceptual | Real-world |
| Status | Reference | Actual standard |
π€ Interview Qs:
- Q: Which model is used in practice: OSI or TCP/IP?
π A: TCP/IP. OSI is a theoretical reference. - Q: Why study OSI if we use TCP/IP?
π A: OSI provides better granularity and helps in troubleshooting discussions.
β‘ Quick Cheat-Sheet
- Layer 1: Physical β Bits (Cables, Wi-Fi)
- Layer 2: Data Link β Frames (MAC, Switches)
- Layer 3: Network β Packets (IP, Routers)
- Layer 4: Transport β Segments (Ports, TCP/UDP)
- Layer 7: Application β Data (Protocols like HTTP, DNS)
TCP Header Format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset | Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
π Common Interview Traps
- Confusing OSI vs TCP/IP layers
- Eg: Session & Presentation are not in TCP/IP.
- Mixing application vs application-layer protocol
- Eg: Browser = app, HTTP = protocol.
- Forgetting port examples
- Eg: 80/443 (HTTP/HTTPS), 53 (DNS), 25 (SMTP).
- Assuming MAC = same as IP
- MAC = device, IP = logical routing address.
π― Final Takeaway
The TCP/IP model is not just theory. Itβs what real-world networks (including the internet) use daily.
From an interviewerβs perspective:
- Expect layer-wise explanations.
- Be ready to compare OSI vs TCP/IP.
- Be comfortable explaining encapsulation, TCP vs UDP, and port usage.