TCP/IP & OSI Model

Understand how the OSI and TCP/IP models layer network functions, how data travels from app to wire.

Easy 45m 4 tasks

Learning Objectives

  • Name and describe all 7 OSI layers
  • Map TCP/IP 4-layer model to OSI equivalents
  • Explain the TCP 3-way handshake
  • Identify key protocols and port numbers at each layer

The OSI Model

The OSI (Open Systems Interconnection) model is a conceptual framework dividing network communication into 7 layers. Each layer has a specific job and communicates with the layers above and below it.

Layer 7 — Application   → HTTP, DNS, FTP, SMTP
Layer 6 — Presentation  → TLS/SSL, JPEG, ASCII
Layer 5 — Session       → NetBIOS, RPC
Layer 4 — Transport     → TCP, UDP
Layer 3 — Network       → IP, ICMP, ARP
Layer 2 — Data Link     → Ethernet, WiFi (802.11)
Layer 1 — Physical      → Cables, radio waves, bits

Mnemonic: "All People Seem To Need Data Processing"

Layer Details

Layer 7 — Application

The interface between the user/app and the network. Protocols: HTTP/S (web), DNS (name resolution), FTP (file transfer), SMTP/IMAP (email).

Layer 4 — Transport

Provides end-to-end communication between processes using port numbers.

Feature TCP UDP
Connection Yes (3-way handshake) No
Reliability Guaranteed delivery, retransmit Best-effort
Order Sequenced Not sequenced
Speed Slower Faster
Use case HTTP, SSH, FTP DNS, VoIP, gaming, video

TCP 3-Way Handshake:

Client  SYN       Server
Client  SYN-ACK   Server
Client  ACK        Server
[Connection established]

Layer 3 — Network

Routes packets across multiple networks using IP addresses. Key protocols: IP, ICMP (ping/traceroute), OSPF, BGP.

Layer 2 — Data Link

Transfers frames within a single network segment using MAC addresses. Ethernet uses CSMA/CD. WiFi uses CSMA/CA.

TCP/IP Model (4 Layers)

OSI                    TCP/IP
────────────────────   ──────────────
Application (7)  ┐
Presentation (6) │ → Application
Session (5)      ┘
Transport (4)    → Transport
Network (3)      → Internet
Data Link (2)    ┐
Physical (1)     ┘ → Network Access

Encapsulation

As data moves down the stack, each layer adds a header (and sometimes a trailer):

App data
     [TCP header] + data         (segment)
     [IP header] + segment       (packet)
     [Eth header] + packet + [FCS]  (frame)
     bits on the wire

At the receiving end, each layer strips its header (de-encapsulation).

Common Port Numbers

Port Protocol Service
20/21 TCP FTP
22 TCP SSH
23 TCP Telnet
25 TCP SMTP
53 UDP/TCP DNS
80 TCP HTTP
443 TCP HTTPS
3389 TCP RDP

The OSI (Open Systems Interconnection) model is a conceptual framework dividing network communication into 7 layers. Each layer has a specific job and only talks to adjacent layers.

OSI 7-Layer Stack
Mnemonic: "All People Seem To Need Data Processing" — Application, Presentation, Session, Transport, Network, Data Link, Physical
PDUs (Protocol Data Units) per Layer
Layer 7–5 — Data
Layer 4 — Segment
Layer 3 — Packet
Layer 2 — Frame
Layer 1 — Bits
✦ Answer the questions to complete this task

At which OSI layer does TCP operate?

A 'packet' is the PDU (Protocol Data Unit) at which OSI layer?

Two core Transport layer protocols — TCP (reliable) and UDP (fast). Choosing the right one depends on the application's needs.

🔵 TCP — Transmission Control

  • Connection-oriented (3-way handshake)
  • Guaranteed delivery — retransmits lost packets
  • In-order delivery
  • Flow control and congestion control
  • Slower but reliable
✦ HTTP/S, SSH, FTP, Email

🟡 UDP — User Datagram Protocol

  • Connectionless — no handshake
  • Best-effort delivery (may drop packets)
  • No ordering guarantee
  • No flow control
  • Faster, lower overhead
✦ DNS, VoIP, Video streaming, Gaming
✦ Answer the questions to complete this task

Which protocol uses a 3-way handshake before sending data?

DNS typically uses which transport protocol?

Before TCP transfers data, it establishes a connection using a 3-way handshake. This ensures both sides are ready and agrees on sequence numbers.

TCP 3-Way Handshake
1
SYN — Client initiates

Client sends a SYN (synchronise) packet with a random sequence number (ISN). "I want to connect, my starting seq is 1000."

2
SYN-ACK — Server acknowledges

Server replies with SYN-ACK: acknowledges client's seq (1001) and sends its own ISN. "Got it! My starting seq is 5000."

3
ACK — Connection established

Client acknowledges server's seq (5001). Connection is now open. Data can flow.

# Watch a real TCP handshake: sudo tcpdump -i any tcp and host google.com -n # Look for: Flags [S] = SYN # Flags [S.] = SYN-ACK # Flags [.] = ACK
✦ Answer the questions to complete this task

What is the first packet sent in a TCP 3-way handshake?

After the handshake completes, the connection state is:

Port numbers identify the specific service/application a packet is destined for. Ports 0–1023 are well-known, reserved for standard services.

PortProtocolServiceEncrypted?
20/21TCPFTP (File Transfer)No (use SFTP)
22TCPSSH (Secure Shell)Yes ✓
23TCPTelnetNo ⚠
25TCPSMTP (Email send)No (use 587/465)
53UDP/TCPDNSNo (use DoH/DoT)
80TCPHTTP (Web)No ⚠
443TCPHTTPS (Web)Yes ✓
3389TCPRDP (Remote Desktop)Yes (TLS)
⚠ Security: Ports 23 (Telnet) and 80 (HTTP) transmit data in plaintext. Always prefer SSH (22) and HTTPS (443).
✦ Answer the questions to complete this task

Which port does HTTPS use?

Port 22 is used by which service?

Why should you avoid using Telnet (port 23)?

💪 Exercises & Challenges

⚙️ Practical Easy +25 XP

Packet Capture with tcpdump

## Task: Observe TCP Handshake Use `tcpdump` to capture and observe a real TCP 3-way handshake. ### Steps **Step 1 — Start capture:** ```bash sudo tcpdump -i any -n tcp port 80 -c 20 ``` **Step 2

Start →
🚩 Challenge Easy +50 XP

Protocol Identification

Analyse this packet header excerpt: ``` Src IP: 10.0.0.5 Dst IP: 10.0.0.1 Proto: 6 Src Port: 54231 Dst Port: 22 Flags: [S] Seq: 1000 ``` **Question**: What service is being connected to, a

Start →