Beginner · Networking for security · topic 6 of 43 · 30 min
TCP/IP and the network layers
Explanation
Why defenders learn networking first
Almost every attack travels over a network: a phishing email, a stolen password used from another country, malware calling home, data being copied out. If you cannot read network data, you cannot see these attacks. Security analysts spend much of their day looking at IP addresses, ports and protocols in logs.
Layers: one job each
Sending data over a network is split into layers. Each layer does one job and hands its work to the next. This makes networks easier to build and to troubleshoot: when something breaks, you ask "which layer?"
There are two common models. The OSI model has 7 layers and is used for teaching and talking. The TCP/IP model has 4 layers and is how the internet really works. They describe the same thing at different detail.
| OSI layer | TCP/IP layer | Job | Examples | Security example |
|---|---|---|---|---|
| 7 Application, 6 Presentation, 5 Session | Application | What the program says | HTTP, DNS, SMTP, SSH, TLS | Phishing site, SQL injection |
| 4 Transport | Transport | Deliver to the right program (port), reliably or fast | TCP, UDP | Port scans, SYN floods |
| 3 Network | Internet | Route packets between networks using IP addresses | IP, ICMP | IP spoofing, ping floods |
| 2 Data link, 1 Physical | Link | Move frames on the local network using MAC addresses; signals on cable or radio | Ethernet, Wi-Fi, ARP | ARP spoofing, Wi-Fi snooping |
Encapsulation
Encapsulation means each layer wraps the data from the layer above with its own header (a label with addresses and control information). Your web request becomes a TCP segment, inside an IP packet, inside an Ethernet or Wi-Fi frame. The receiver unwraps it layer by layer.
TCP and UDP
The transport layer has two main protocols. A protocol is an agreed set of rules for talking.
- TCP (Transmission Control Protocol): reliable. It sets up a connection, numbers the data, resends anything lost, and delivers it in order. Used by web, email, SSH and file transfer.
- UDP (User Datagram Protocol): fast and simple, with no connection and no resending. Used by DNS lookups, video calls, online games and streaming, where speed matters more than a lost packet.
The TCP three-way handshake
Before TCP sends data, the two sides agree to talk using three small packets, each marked by flags (on/off bits in the TCP header):
Client → Server SYN "I want to talk"
Server → Client SYN-ACK "OK, I hear you, do you hear me?"
Client → Server ACK "Yes. Let's start."
... data ...
Either side FIN "I am done" (polite close)
Either side RST "Stop now" (reset)Defenders use this. Thousands of SYN packets with no final ACK can mean a SYN flood (a denial-of-service attack that fills the server's waiting list). One source sending a SYN to hundreds of different ports in a minute usually means a port scan.
Common mistakes
- Thinking a firewall at layer 3/4 can stop a phishing page. That is an application-layer problem; it needs web filtering and user awareness.
- Mixing up MAC and IP addresses. A MAC address identifies a network card on the local network; an IP address identifies a device across networks.
- Assuming UDP traffic is harmless because it is "connectionless". DNS over UDP is used in many attacks.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
TCP/IP and the network layers · 1/7
Almost every attack travels over a network, so defenders must read network data.
Prefer a video by a teacher? Find free videos on “OSI model vs TCP IP model TCP three way handshake explained” on YouTube ↗
In real life: Reading a firewall log line
A SOC analyst at a Bengaluru IT company sees this in the firewall log. Layer 3 gives the IP addresses, layer 4 gives TCP and the ports, and the flags show only SYN packets to many ports from one outside address. That is a port scan from the internet, which is common and usually blocked, but it is worth checking that nothing answered.
2026-03-14 02:11:05 DENY TCP 198.51.100.23:51514 -> 203.0.113.10:22 flags=S
2026-03-14 02:11:05 DENY TCP 198.51.100.23:51515 -> 203.0.113.10:23 flags=S
2026-03-14 02:11:05 DENY TCP 198.51.100.23:51516 -> 203.0.113.10:3389 flags=SPractice (0/3 done)
Which protocol works at the transport layer?
A list of flag strings from one TCP conversation is given, in order, like ["SYN", "SYN-ACK", "ACK", "PSH", "FIN"]. Write handshake_complete(flags) that returns True only if the first three entries are exactly "SYN", "SYN-ACK", "ACK".
One outside IP sends single SYN packets to ports 1 to 1000 on your server in 30 seconds. What is it most likely?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- IP addresses, subnets and CIDRNetworking for security · same module
- Ports and protocolsNetworking for security · same module
- DNS: the internet's phone bookNetworking for security · same module
- The TCP/IP model and encapsulationComputer Networking (CCNA level) · How networks work
- TCP, UDP and port numbersComputer Networking (CCNA level) · How networks work
- The OSI modelComputer Networking (CCNA level) · How networks work
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
How many layers does the OSI model have?
Answer: 7
OSI has 7 layers; the practical TCP/IP model has 4.
Which protocol is used by most DNS lookups because it is fast?
Answer: UDP
DNS queries normally use UDP port 53, falling back to TCP for large answers.
What is the correct order of the TCP handshake?
Answer: SYN, SYN-ACK, ACK
SYN, then SYN-ACK, then ACK.
What does a MAC address identify?
Answer: A network card on the local network
MAC addresses work at the link layer on the local network.
Wrapping data with a header at each layer is called…
Answer: Encapsulation
Encapsulation: each layer adds its own header around the data.
Which layer of the 4-layer TCP/IP model matches OSI Layer 3?Related
Answer: Internet
The Internet layer, where IP lives, matches the OSI network layer.
What identifies one TCP connection uniquely?Related
Answer: The client and server IP addresses and ports
A connection is the pair of sockets: client IP and port plus server IP and port.
A PC shows no link light on its network port. Which layer should you check first?Related
What does no switchport do on a layer 3 switch port?Related
Answer: Makes it a routed port that can take an IP address
no switchport turns the port into a layer 3 routed port, like a router interface.
From Inter-VLAN routing
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Networking for security” before its exam: IP addresses, subnets and CIDR, Ports and protocols, DNS: the internet's phone book, HTTP, HTTPS and TLS.
- Module 2 exam: Networking for security · 12 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Systems and cryptography. 43 topics left in the course before the final exam.