LESSON 14 · BEGINNER5 min read

How Data Travels Across a Network

Use a practical layered model to understand encapsulation, addressing, ports, and the difference between TCP and UDP.

OWASP Top 10 · MITRE ATT&CK · NIST CSF 2.0Free to readModule 4 of 14
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Explain the practical role of the link, internet, transport, and application layers.
  • Describe encapsulation and the difference between MAC addresses, IP addresses, and ports.
  • Compare TCP and UDP and recognise their common security trade-offs.
  • Trace a connection using command-line tools and interpret the output.

01Networks Are Layers of Agreements

A network is a stack of agreements. At the bottom, hardware moves electrical, optical, or radio signals between devices. Above that, link-layer protocols such as Ethernet and Wi-Fi deliver frames on a local segment. The internet layer adds logical addressing so packets can cross many networks. The transport layer identifies conversations between applications. The application layer defines the meaning of the data, whether that is HTTP, DNS, SSH, or something custom.

The OSI seven-layer model is a teaching tool; the TCP/IP model is closer to what software actually implements. For security work, the practical version is enough: physical and link, internet, transport, and application. When something fails, ask which layer is responsible. A cable problem, a wrong IP address, a blocked port, and a malformed HTTP request produce different symptoms.

This layered design is powerful because each layer can be inspected and controlled independently. A firewall can block a port without understanding HTTP. A web application firewall can inspect a request without caring which router carried it. A TLS library can protect data without knowing whether the application is a bank or a chat app. Attackers also work layer by layer: they poison DNS, hijack sessions, exploit application logic, or exhaust network capacity.

02Encapsulation, MAC Addresses, IP Addresses, and Ports

Encapsulation is the process of wrapping data in successive headers as it moves down the stack. An HTTP request becomes a TCP segment, then an IP packet, then an Ethernet frame. Each layer adds the information its own equipment needs. At the receiving end, the process reverses: the frame header is removed, the packet is routed, the segment is reassembled, and the application receives the request.

A MAC address identifies a network interface on a local link. An IP address identifies a host across networks. A port identifies a service or conversation on that host. A typical HTTPS connection to a server uses TCP port 443. Your browser picks an ephemeral source port, often in the 49152-65535 range, so replies can be matched to the right tab.

This distinction matters during investigation. Seeing traffic to port 443 tells you the transport destination, not whether the content is safe. Seeing a connection from an unfamiliar IP tells you where packets claim to come from, not who sent them. Addresses can be spoofed, proxied, or shared through NAT. Evidence becomes useful when you combine multiple layers and time-correlated logs.

encapsulation.txtPlain text
Application   HTTP GET /accountTransport     TCP source 51342 -> destination 443, sequence numbersInternet      IP source 10.10.10.20 -> destination 203.0.113.10Link          Ethernet source aa:bb:cc:dd:ee:ff -> gateway 11:22:33:44:55:66At each hop, the link header changes.The IP addresses usually stay the same end to end.The port identifies the service and the conversation.

03TCP, UDP, and the Handshake

TCP provides a reliable, ordered byte stream. It establishes a connection with a three-way handshake: the client sends SYN, the server replies SYN-ACK, and the client sends ACK. It retransmits lost data, manages flow control, and closes connections gracefully. Most web, email, SSH, and database traffic uses TCP because applications need complete, ordered data.

UDP is connectionless and does not guarantee delivery or order. That makes it suitable for DNS queries, real-time voice and video, and protocols that implement their own reliability. UDP is not automatically insecure, but it is easier to spoof source addresses because there is no handshake to prove reachability.

Security controls differ by transport. A stateful firewall can allow outbound TCP connections and their return traffic without opening a permanent inbound hole. Rate limiting a UDP service is important because reflection and amplification attacks abuse connectionless protocols. When you troubleshoot, confirm the protocol before assuming a port is simply 'open' or 'closed'.

observe-connections.shShell
# Show listening TCP and UDP sockets with process names.sudo ss -tulpn# Show active connections and their states.ss -tunap# Follow one HTTPS request and display the request and response headers.curl -v https://example.com/ -o /dev/null
Outputstdout
Netid State  Local Address:Port   Peer Address:Port
tcp   LISTEN 0.0.0.0:22           0.0.0.0:*
tcp   LISTEN 127.0.0.1:3000        0.0.0.0:*
udp   UNCONN 127.0.0.53:53         0.0.0.0:*
* Connected to example.com (203.0.113.10) port 443
> GET / HTTP/1.1
< HTTP/1.1 200 OK

04Read the Path, Not Just the Port

A connection is a path, not a single event. The client resolves a name, chooses an address, opens a socket, completes a handshake, negotiates TLS, sends a request, and receives a response. Each step can fail or be attacked. DNS can return a malicious address. A proxy can terminate TLS and inspect content. A load balancer can hide the real origin. A captive portal can intercept the first request.

When you investigate, write down the five-tuple: source IP, source port, destination IP, destination port, and protocol. Add timestamps and process names where possible. Then ask which device in the path could have observed or changed the traffic. This habit turns vague suspicion into a testable hypothesis.

You will use this mental model for the rest of the course. Web attacks travel over HTTP. Reconnaissance often begins with DNS and port scanning. Incident response depends on network logs. Cloud security depends on understanding which network boundary a service crosses. The layers are not academic; they are the map you use to find evidence.

LET IT CLICK

The ideas worth keeping.

  • Networks are layered; troubleshooting improves when you identify which layer is failing.
  • MAC addresses work on a local link, IP addresses route across networks, and ports identify services.
  • TCP is reliable and connection-oriented; UDP is lightweight and connectionless.
  • A connection is a path through DNS, routing, transport, and application logic, not just an open port.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.

01

Exercise 1: Map a request to layers

A browser opens https://shop.example.com. For each step, name the layer or protocol involved: resolving the name, opening a connection to port 443, encrypting the request, and sending the HTTP GET. Then explain which layer a firewall blocking port 443 operates on.

Explore a worked solution
one_possible_solution.mdCybersecurity
Name resolution: application-layer DNS (usually over UDP port 53). Opening a connection: transport-layer TCP with a three-way handshake. Encryption: TLS, which sits between the transport and application layers and protects the HTTP payload. Sending the request: application-layer HTTP. A firewall blocking port 443 makes a transport-layer decision based on TCP port number; it does not need to understand HTTP or TLS content.

The same request crosses several layers. Naming the layer helps you choose the right tool and interpret the right logs.

02

Exercise 2: Interpret sockets

You see a listening service on 0.0.0.0:8080 and another on 127.0.0.1:3000. Explain the difference in exposure and give one reason each might be intentional.

Explore a worked solution
one_possible_solution.mdCybersecurity
0.0.0.0:8080 listens on every IPv4 interface, so other hosts on reachable networks may connect unless a firewall blocks them. It might be intentional for a public web service or a container that needs external access. 127.0.0.1:3000 listens only on the loopback interface, so it is reachable only from the local machine. It might be intentional for a development server or an internal admin UI that should never be exposed. Always confirm with firewall rules and the application's purpose.

Bind address is a security boundary. A service on loopback is not automatically safe, but it has a much smaller network exposure than a service on all interfaces.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 4 answered
01What does a port number identify?
02Which sequence describes the TCP three-way handshake?
03Why is UDP often used for DNS queries?
04What is encapsulation?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.