Post

TCP/IP Model

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:

  1. πŸ“– Detailed Explanation of Each Layer
  2. 🎀 Interview Q&A (Interviewer’s POV)
  3. ⚑ 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.

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.html to 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

  1. Application Layer (HTTP)
    • Browser creates an HTTP request:
      1
      
      GET /index.html HTTP/1.1
      
  2. Transport Layer (TCP)
    • Adds source port (random, e.g., 49152) and destination port (80 or 443).
    • Handles 3-way handshake, reliability, retransmission.
  3. Network Layer (IP)
    • Adds source & destination IP addresses.
  4. 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)

  1. App Layer: Data created (web request).
  2. Transport Layer: Adds port numbers β†’ Segment.
  3. Network Layer: Adds IP addresses β†’ Packet.
  4. Data Link Layer: Adds MAC + trailer β†’ Frame.
  5. 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

FeatureOSI ModelTCP/IP Model
Layers75
UsageConceptualReal-world
StatusReferenceActual 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

  1. Confusing OSI vs TCP/IP layers
    • Eg: Session & Presentation are not in TCP/IP.
  2. Mixing application vs application-layer protocol
    • Eg: Browser = app, HTTP = protocol.
  3. Forgetting port examples
    • Eg: 80/443 (HTTP/HTTPS), 53 (DNS), 25 (SMTP).
  4. 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.

πŸ™Œ Connect With Me

GitHub LinkedIn YouTube Gmail

This post is licensed under CC BY 4.0 by the author.