The OSI and TCP/IP Models
Network models divide communication into layers, giving practitioners a shared language for where devices operate, where attacks occur and which controls apply. This lesson explains the OSI and TCP/IP models, encapsulation and the TCP and UDP transport protocols.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the layers of the OSI model and example attacks at each.
- Map the TCP/IP model to the OSI model.
- Explain encapsulation.
- Compare TCP and UDP.
Why layered models matter
Network communication involves many tasks: turning bits into signals, delivering frames on a local network, routing packets across networks, ensuring reliable delivery and presenting data to applications. Layered models divide these tasks so that each layer provides services to the one above and relies on the one below. For security, layers tell you what a device can see and control: a switch makes decisions on MAC addresses at layer 2, a router on IP addresses at layer 3, and a web application firewall on HTTP content at layer 7. Attacks are described the same way, such as a layer 2 ARP spoofing attack or a layer 7 application flood.
Which OSI layer?
The OSI model
The Open Systems Interconnection (OSI) model, published by ISO, has seven layers. The following table lists them with their data units, functions, example protocols and devices, and example attacks.
| Layer | Data unit | Function | Examples | Example attacks |
|---|---|---|---|---|
| 7 Application | Data | Network services for applications | HTTP, DNS, SMTP, SSH | SQL injection, application floods |
| 6 Presentation | Data | Formatting, encoding, encryption | TLS (often placed here), character encoding | SSL stripping |
| 5 Session | Data | Establishing and managing sessions | RPC, NetBIOS sessions | Session hijacking |
| 4 Transport | Segment (TCP) or datagram (UDP) | End-to-end delivery, ports, reliability | TCP, UDP | SYN floods, port scanning |
| 3 Network | Packet | Logical addressing and routing | IP, ICMP, IPsec; routers | IP spoofing, ICMP floods |
| 2 Data link | Frame | Local delivery, MAC addressing | Ethernet, 802.11, ARP; switches | ARP spoofing, MAC flooding, VLAN hopping |
| 1 Physical | Bits | Signals on the medium | Cables, radio, hubs | Tapping, jamming, cutting cables |
A common memory aid from layer 1 upwards is "Please Do Not Throw Sausage Pizza Away".
The following diagram places three security events at their layers of the OSI model.

The OSI layers
The TCP/IP model and encapsulation
The TCP/IP model, on which the internet is actually built, has four layers. The network access (link) layer corresponds to OSI layers 1 and 2; the internet layer to layer 3 (IP); the transport layer to layer 4 (TCP and UDP); and the application layer to OSI layers 5 to 7.
As data moves down the layers on the sending host, each layer adds its own header, a process called encapsulation: application data is wrapped in a TCP segment with port numbers, then an IP packet with addresses, then an Ethernet frame with MAC addresses. The receiver removes the headers in reverse (de-encapsulation). Security tools inspect different headers: a packet filter reads IP and port fields, while deep packet inspection examines the payload.
TCP and UDP
The Transmission Control Protocol (TCP) is connection-oriented and reliable. It sets up a connection with the three-way handshake (the client sends SYN, the server replies SYN-ACK, the client sends ACK), numbers segments, acknowledges them, retransmits losses and closes connections with FIN or aborts them with RST. Applications that need complete, ordered data use it, such as web, email and file transfer.
The User Datagram Protocol (UDP) is connectionless: it sends datagrams without a handshake, acknowledgement or ordering, which makes it fast and suited to DNS queries, voice, video and streaming. Because there is no handshake, UDP source addresses are easy to spoof, which is why UDP services such as DNS and NTP are abused in reflection and amplification DDoS attacks.
TCP or UDP?
Which layer?
Name the OSI layer of each: (1) an attacker floods a switch's MAC address table so it forwards frames to all ports; (2) a firewall rule blocks TCP port 23; (3) a web application firewall blocks a request containing a SQL injection string.
(1) MAC flooding is a layer 2 (data link) attack. (2) Filtering on a port is a layer 4 (transport) decision, typically combined with layer 3 addresses. (3) Inspecting HTTP content is layer 7 (application).
Half-open connections
A web server's connection table fills with thousands of connections from many addresses that sent SYN and never completed the handshake. What is happening?
A SYN flood: the attacker exploits the TCP three-way handshake by sending SYNs, often with spoofed sources, so the server holds half-open connections and runs out of resources. Countermeasures include SYN cookies, which avoid reserving resources until the handshake completes, rate limiting, firewalls and upstream DDoS protection.
At which OSI layer does ARP spoofing operate?
Show answer
Layer 2, the data link layer, because it manipulates the mapping between IP addresses and MAC addresses on a local network.
Exam Tips
Remember for the exam
- Switches: layer 2; routers: layer 3; WAFs and proxies: layer 7.
- TCP/IP's four layers map to OSI 1-2, 3, 4 and 5-7.
- TCP uses the SYN, SYN-ACK, ACK handshake; UDP is connectionless and easy to spoof.