Skip to content
Visual explainer 3h to learn 4 steps

OSI & TCP/IP models

Place protocols, devices and attacks on the right OSI and TCP/IP layer.

By Invicly Tech, , in Cyber Security Fundamentals. About 9 minutes to read.

Topic 6 of 49

In short

The OSI model splits networking into seven layers and the TCP/IP model into four. Defenders use the layers to place protocols, devices and attacks precisely, which makes troubleshooting and threat analysis systematic rather than guesswork.

Explained simply

When two computers talk, many jobs happen at once: turning data into signals, finding the right machine, making sure nothing is lost, and understanding the message. Network models split these jobs into layers, so each layer can do one job and trust the layers below for the rest.

Sending a parcel is a good picture. You write a letter (the application data), put it in an envelope with a name (transport), the post office adds a street address (network), a van carries it between depots (data link), and roads carry the van (physical). Each step adds its own label and does not care what is inside.

The OSI model has seven layers and is mainly used for teaching and talking. The TCP/IP model has four layers and matches how the internet really works. Security people use both to say exactly where a problem lives, for example "this is a layer 2 attack on the local network".

TCP and UDP are the two main transport protocols. TCP is like a phone call: it sets up a connection, numbers every piece and resends lost ones. UDP is like shouting across a room: fast, no setup, and no guarantee anyone heard.

Press Play on a diagram to walk through it one step at a time.

LayersOSI model
  1. 1
    7 Application

    HTTP, DNS, SMTP.

  2. 2
    6 Presentation

    Encoding and encryption.

  3. 3
    5 Session

    Sessions between hosts.

  4. 4
    4 Transport

    TCP and UDP.

  5. 5
    3 Network

    IP and routing.

  6. 6
    2 Data link

    MAC addresses and switches.

  7. 7
    1 Physical

    Cables and signals.

FlowWrapping one web request on the way out
  1. 1
    HTTP request

    GET /login, created by the browser.

  2. 2
    + TCP header

    Ports 51544 -> 443, sequence numbers.

  3. 3
    + IP header

    192.168.1.20 -> 93.184.215.14.

  4. 4
    + Ethernet header

    Laptop MAC -> router MAC.

  5. 5
    Bits on the wire

    Electrical or radio signals.

CompareTCP vs UDP from a defender's view
TCP
  • Handshake, so spoofed sources rarely complete it
  • Flags reveal scans and floods
  • Used by HTTP(S), SSH, SMB, RDP
  • Streams can be rebuilt in Wireshark
UDP
  • No handshake, so source IPs are easy to fake
  • Used in reflection and amplification DDoS
  • Used by DNS, NTP, DHCP, many games
  • Also used for tunnelling data out via DNS

In depth

Encapsulation: wrapping at every layer

As data goes down the layers, each one adds a header with its own information. Your browser's HTTP request becomes the payload of a TCP segment, which adds source and destination ports. That becomes the payload of an IP packet, which adds source and destination IP addresses. That becomes the payload of an Ethernet frame, which adds MAC addresses (hardware addresses of network cards).

At the other end, each layer removes its header and passes the rest up. Tools like Wireshark show these layers as nested sections, which is why understanding encapsulation makes packet captures readable.

  • Data at application layer
  • Segment at transport (TCP) or datagram (UDP)
  • Packet at network layer
  • Frame at data link layer
  • Bits on the wire

Mapping OSI to TCP/IP

The TCP/IP model merges some OSI layers. OSI layers 5, 6 and 7 (session, presentation, application) become one application layer. OSI layer 4 is the transport layer in both. OSI layer 3 is called the internet layer. OSI layers 1 and 2 become the link (or network access) layer.

In practice, people still say "layer 7" for application traffic and "layer 3" for IP, even when using TCP/IP. A "layer 7 firewall" understands web requests, while a "layer 3/4 firewall" only sees addresses and ports.

TCP flags tell the story

Every TCP segment carries flags. SYN asks to start a connection. ACK acknowledges data. FIN politely closes a connection. RST abruptly resets it. PSH and URG are less common.

Defenders read flags to understand behaviour. Many SYNs to different ports with no completed handshakes suggest a port scan. Lots of RST replies mean ports are closed or a firewall is rejecting traffic. A flood of SYNs from many sources to one server without the final ACK is a SYN flood, a denial of service attack that fills the server's table of half-open connections.

SequenceTCP flags in one connection
Client
Server
  1. 1SYN
    Client to Server: SYN
  2. 2SYN-ACK
    Server to Client: SYN-ACK
  3. 3ACK (handshake done)
    Client to Server: ACK (handshake done)
  4. 4Data with PSH, ACK
    Client to Server: Data with PSH, ACK
  5. 5FIN
    Client to Server: FIN
  6. 6ACK, then its own FIN
    Server to Client: ACK, then its own FIN
  7. 7ACK (closed)
    Client to Server: ACK (closed)

Placing attacks and defences on layers

Layers give you a map for attacks and controls. Layer 1: cutting cables or plugging into an open wall port; defence is physical security and port control. Layer 2: ARP spoofing or MAC flooding on a switch; defences include dynamic ARP inspection and port security. Layer 3: IP spoofing and routing attacks; defences include ingress filtering. Layer 4: SYN floods and port scans; defences include SYN cookies and firewalls. Layer 7: SQL injection and phishing; defences include secure code, WAFs and user training.

LayersAttacks and defences by layer
  1. 1
    Layer 7 Application

    SQL injection, phishing; secure code, WAF, training

  2. 2
    Layer 4 Transport

    SYN floods, port scans; SYN cookies, firewalls

  3. 3
    Layer 3 Network

    IP spoofing, routing attacks; ingress filtering

  4. 4
    Layer 2 Data link

    ARP spoofing, MAC flooding; DAI, port security

  5. 5
    Layer 1 Physical

    Cut cables, open wall ports; physical security

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Name the seven OSI layers~45m
  2. 2
    Map OSI to the TCP/IP model~45m
  3. 3
    Explain the TCP three-way handshake~45m
  4. 4
    Compare TCP and UDP~45m

Key points

  • OSI has seven layers; TCP/IP collapses them into four.
  • TCP sets up a connection with a three-way handshake.
  • UDP is connectionless and faster but unreliable.
  • Placing an attack on a layer suggests where to defend.

Key terms

Tap a card to flip it. 0/4 known

Examples

Reading a TCP handshake in a capture

Step 1: Packet 1 shows 10.0.0.5 -> 10.0.0.10, port 51000 -> 22, flag SYN: the client asks to talk to SSH. Step 2: Packet 2 shows the reverse direction with SYN, ACK: the server agrees. Step 3: Packet 3 shows ACK from the client: connection open. Step 4: SSH data follows. If instead packet 2 had shown RST, ACK, the port was closed. If there was no reply at all, a firewall probably dropped the SYN silently.

text
No. Source     Destination  Proto Info
1   10.0.0.5   10.0.0.10    TCP   51000 -> 22 [SYN] Seq=0
2   10.0.0.10  10.0.0.5     TCP   22 -> 51000 [SYN, ACK] Seq=0 Ack=1
3   10.0.0.5   10.0.0.10    TCP   51000 -> 22 [ACK] Seq=1 Ack=1
4   10.0.0.10  10.0.0.5     SSH   Server: Protocol (SSH-2.0-OpenSSH_9.6)

Placing an incident on the right layer

Users on one office floor report slow internet and certificate warnings. Step 1: Certificate warnings suggest someone is intercepting HTTPS. Step 2: Only one floor is affected, so the cause is local, likely layer 2. Step 3: On an affected PC, run "arp -a": the gateway IP shows the same MAC address as another PC on the floor. Step 4: Conclusion: ARP spoofing (layer 2) enabling a man-in-the-middle. Step 5: Defence: unplug the rogue machine, enable dynamic ARP inspection on the switch, and investigate how it got there.

Quick reference

  • OSI top to bottom: Application, Presentation, Session, Transport, Network, Data link, Physical
  • TCP/IP: Application, Transport, Internet, Link
  • Data unit names: segment (TCP), packet (IP), frame (Ethernet)
  • SYN -> SYN-ACK -> ACK opens TCP; FIN closes politely; RST slams the door
  • Many SYNs, few handshakes, many ports = likely port scan
  • Layer 2 attacks stay on the local network; layer 7 attacks travel across the internet

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which header carries MAC addresses?

Question 2

2A client sends SYN and gets RST, ACK back. What does this most likely mean?

Question 3

3Why is UDP popular for reflection DDoS attacks?

Question 4

4Which OSI layers are merged into the TCP/IP application layer?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Place each item on an OSI layer: switch, router, TLS encryption, HTTP, Ethernet cable, TCP port 443.

  2. Exercise 2medium

    In a lab VM, capture traffic in Wireshark while visiting one HTTP site, then find and screenshot the three-way handshake. Note the ports used.

  3. Exercise 3hard

    Make a table of five attacks, one per layer (1, 2, 3, 4, 7). For each, give one sign you would see in logs or captures and one defence.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I really need to memorise the OSI layers?
Yes, at least the names and numbers. Interviews and certifications ask about them, and colleagues will say things like "layer 7 attack" expecting you to know what that means.
Where does TLS fit in the OSI model?
It does not map neatly. It is often placed at layer 6 (presentation) because it encrypts data, but it runs on top of TCP and below HTTP, so some people call it layer 4.5.
Is UDP less secure than TCP?
Neither is encrypted on its own. UDP is easier to spoof and abuse for amplification attacks, but security comes from what runs on top, such as TLS, DTLS or QUIC.

Go deeper

ShareXLinkedInWhatsApp