Networking

OSI Model

Updated 2026-06-17

The OSI model splits "how data travels across a network" into 7 layers. Each layer has one job, and only talks to the layer right above and below it — it trusts the lower layers and doesn't care how they work. Real networks run on TCP/IP, but everyone still explains and troubleshoots using these 7 layers, so it's the thing to know.

  • OSI = Open Systems Interconnection. "Open" means built on public, vendor-neutral standards so any maker's gear works together.
  • It's a reference model — a way of thinking and a shared vocabulary, not the actual software. The standard is ISO/IEC 7498-1 (same text as ITU-T X.200), published in 1984. The 7-layer idea came from Charles Bachman / Hubert Zimmermann in the late 1970s.
  • ISO also wrote real OSI protocols to go with it (TP0–TP4, CLNP, X.400, X.500…), but they lost to TCP/IP. Only a few (X.500 → LDAP, IS-IS, ASN.1) survived.

The 7 layers

7ApplicationData
6PresentationData
5SessionData
4TransportSegment
3NetworkPacket
2Data LinkFrame
1PhysicalBits
Layer 7 is closest to me; layer 1 is the wire. Coral = software side (7–5), grey = network side (4–1).

Two ways to remember the order:

  • Top to bottom (7 → 1): All People Seem To Need Data Processing.
  • Bottom to top (1 → 7): Please Do Not Throw Sausage Pizza Away.

Quick split: layers 7–5 are software on my device (the app side), layers 4–1 move the bits from A to B (the network side).

How data moves

Each layer only really does two things: it talks down to the layer below (to actually send something) and sideways to the same layer on the other machine (in theory). That sideways chat is virtual — the data really goes all the way down my stack, across the wire, and back up the other side.

A few words I'll keep using:

  • PDU (Protocol Data Unit) — the chunk a layer hands to its twin on the other side. Each layer has its own name for it (see below).
  • Header — the small label a layer sticks on the front of the data. Layer 2 also adds a trailer at the end (for an error check).
  • Encapsulation — sending: going down, each layer wraps the data in its own header.
  • Decapsulation — receiving: going up, each layer peels its own header back off.
App dataData= Data
+ TCP header (L4)TCPData= Segment
+ IP header (L3)IPTCPData= Packet
+ frame (L2)EthIPTCPDataFCS= Frame
Going down, each layer wraps the data in its own header. Coming back up, each layer peels its header off again.

Like envelopes: my letter goes in an envelope, then a bigger one, then a bigger one — the other side opens them in reverse.

Data unit (PDU) at each layer:

LayersName
7 · 6 · 5 (App, Pres, Session)Data
4 TransportSegment (TCP) / Datagram (UDP)
3 NetworkPacket
2 Data LinkFrame
1 PhysicalBits

One more pair of words:

  • Connection-oriented — set up first, keep track, guarantee delivery (like a phone call). Example: TCP.
  • Connectionless — just fire it off, no setup, no guarantees (like posting a letter). Examples: UDP, IP.

Layer 7: Application

  • Job: the layer my apps actually talk to. It is not the app itself — it's the protocol the app speaks. A browser is the app; HTTP is the layer-7 protocol it uses.
  • Gives me: web pages, email, file transfer, name lookups, remote login, time sync.
  • Key protocols (and ports):
    • HTTP (80) / HTTPS (443) — the web.
    • DNS (53) — turns names into IP addresses.
    • SMTP (25/587) — send email; IMAP (143) / POP3 (110) — read email.
    • FTP (20/21), SFTP (22, over SSH), TFTP (69) — files.
    • SSH (22) — secure remote shell; Telnet (23) — old, plaintext, avoid.
    • DHCP (67/68) — hands out IP addresses automatically.
    • SNMP (161/162) — monitor devices; NTP (123) — clock sync; LDAP (389) — directories (Active Directory); RDP (3389) — remote desktop.
  • Devices: proxies, WAF (web application firewall), API gateways, layer-7 load balancers.
  • Data unit: Data.

Layer 6: Presentation

  • Job: the "translator". Makes sure data sent by one side is readable by the other.
  • Does:
    • Encryption / decryption — most famously TLS (old name SSL).
    • Compression — shrink data for the trip.
    • Encoding — character sets (ASCII, Unicode/UTF-8, EBCDIC) and file formats (JPEG, PNG, MP4, MP3).
  • Heads up on TLS: it doesn't fit the model cleanly. By function (encryption) it's layer 6, but it actually runs on top of TCP, so people also call it "between 4 and 7." OSI is a guideline, not a law.
  • These days this layer is usually handled inside the app or a library, not as a separate step.
  • Data unit: Data.

Layer 5: Session

  • Job: open, manage, and close the conversation (session) between two machines.
  • Does:
    • Starts and ends sessions cleanly.
    • Dialog control — decides who talks when (one-way, take-turns, or both at once).
    • Checkpoints — drops "bookmarks" into a long transfer so it can resume from the last checkpoint instead of restarting if the link drops.
  • Examples: sockets (the programming interface), RPC, NetBIOS, login sessions.
  • In TCP/IP there is no session layer — apps handle this themselves (e.g. HTTP cookies, TLS session resume).
  • Data unit: Data.

Layer 4: Transport

  • Job: get data end to end between two programs, using port numbers to know which program. This is the first layer that thinks about the whole journey, not just one hop.
  • Does: splits data into pieces, can reassemble in order, and (for TCP) makes it reliable.
  • The two protocols:
    • TCP — connection-based, reliable, ordered. Resends what's lost, controls speed. Used for web, email, files. Heavier.
    • UDP — connectionless, no guarantees, tiny 8-byte header, fast. Used for video calls, streaming, games, DNS, DHCP. Light.

TCP sets up with a 3-way handshake:

ClientServer
SYN"can we talk?" — seq = x
SYN, ACK"yes" — seq = y, ack = x+1
ACK"great, starting" — ack = y+1
TCP's 3-way handshake — both sides agree before any real data is sent.

It closes politely too (FIN → ACK → FIN → ACK), or slams the door with RST.

  • How TCP stays reliable: every byte has a sequence number; the receiver sends ACKs for what it got; missing data is retransmitted. A sliding window (flow control) stops me flooding a slow receiver, and congestion control (slow start, then back off on loss) stops me flooding the network.
  • MSS = the biggest payload TCP puts in one segment, usually 1460 bytes (1500 MTU − 20 IP − 20 TCP).

TCP header (20 bytes, key fields):

FieldSizeWhat it's for
Source / Dest port16 bits eachwhich programs are talking
Sequence number32 bitsbyte position in the stream
Acknowledgement number32 bitsnext byte expected
FlagsSYN ACK FIN RST PSH URGcontrol the connection
Window size16 bitsflow control (how much I can receive)
Checksum16 bitserror check

UDP header is just 4 fields, 8 bytes total: source port, dest port, length, checksum.

  • Ports: well-known 0–1023, registered 1024–49151, ephemeral 49152–65535 (the random port my machine uses as the sender).
  • A socket = IP address + port. A full connection = source IP+port and dest IP+port.
  • Devices: stateful firewalls, layer-4 load balancers.
  • Data unit: Segment (TCP) / Datagram (UDP).

Layer 3: Network

  • Job: get packets from one network to another (routing) using logical IP addresses. Routers live here.
  • Does: logical addressing, picking the best path, splitting packets that are too big (fragmentation), and a hop counter (TTL) so lost packets don't loop forever.

IP addresses:

  • IPv4 — 32-bit, written like 192.168.1.10. About 4.3 billion total, which ran out.
  • Private ranges (RFC 1918) — not used on the public internet: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. 127.0.0.1 is loopback (myself).
  • Subnet mask / CIDR (like /24) splits an address into a network part and a host part.
  • IPv6 — 128-bit (e.g. 2001:db8::1), basically unlimited addresses, simpler fixed header, no broadcast, made to replace IPv4.

IPv4 header (20 bytes, key fields): version, header length, total length, TTL (hop limit), protocol (6 = TCP, 17 = UDP, 1 = ICMP), header checksum, and the source and destination IP.

  • ICMP — the helper protocol for errors and tests. Ping uses it (Echo request/reply); traceroute uses TTL running out at each hop to map the route.
  • Routing:
    • Static — set by hand. Dynamic — routers learn paths automatically.
    • Inside one network (IGP): RIP (simple, hop count, max 15), OSPF (open, builds a full map, picks lowest cost), EIGRP (Cisco).
    • Between networks (EGP): BGP — the routing protocol of the whole internet, runs over TCP port 179.
  • NAT — lets many private IPs share one public IP (what home routers do). Touches L3 (IPs) and L4 (ports).
  • IPsec — encrypts/authenticates IP packets; the basis of many VPNs.
  • Devices: routers, layer-3 switches.
  • Data unit: Packet.
  • Job: move frames between two devices on the same local network, using MAC addresses. Switches live here.
  • Two sublayers: LLC (talks up to layer 3) and MAC (controls who gets to use the wire/airwaves, and does the addressing).
  • Does: framing, MAC addressing, and error detection with an FCS (a CRC checksum in the trailer — bad frames are dropped, not fixed).

MAC address: 48-bit hardware address baked into the network card, e.g. 00:1A:2B:3C:4D:5E. First half = the vendor (OUI), second half = the specific card. FF:FF:FF:FF:FF:FF means broadcast (everyone on the segment).

Ethernet frame (key fields): destination MAC, source MAC, EtherType (e.g. 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6), the payload (46–1500 bytes — 1500 is the MTU), and the FCS error check at the end.

  • ARP — maps an IP address to a MAC address on the local network. "Who has 192.168.1.5?" → the owner replies with its MAC, and I cache it.
  • VLANs (802.1Q) — slice one physical switch into separate virtual networks by adding a 4-byte tag to frames.
  • STP (Spanning Tree, 802.1D) — stops loops in networks with backup links by blocking redundant paths.
  • Getting on the wire: CSMA/CD (old shared Ethernet — listen, send, back off if you collide) and CSMA/CA (Wi-Fi — avoid collisions because radio can't detect them).
  • Switches learn which MAC is on which port (a MAC/CAM table) and forward frames only to the right port. Each port is its own collision domain.
  • Devices: switches, bridges, NICs, wireless access points.
  • Data unit: Frame.

Layer 1: Physical

  • Job: send raw bits as actual signals over the medium — voltages on copper, light in fibre, radio waves in the air.
  • Does: defines cables, connectors, pin layouts, voltage levels, frequencies, data rates, and encoding (how a 1 or 0 becomes a signal — e.g. Manchester, 4B/5B, PAM-5).
  • Media:
    • Copper twisted pair — Cat5e (1 Gbps), Cat6 (1 Gbps, 10 Gbps short runs), Cat6a (10 Gbps full 100 m). Plugs into RJ45. Standard run ~100 m.
    • Fibre — light, immune to interference, long distance. Multi-mode (short, cheaper) vs single-mode (long haul). Connectors LC/SC.
    • Wireless — radio on 2.4 / 5 / 6 GHz (Wi-Fi).
  • Speed words: bandwidth = the max a link could do; throughput = what I actually get; latency = delay; jitter = how much the delay wobbles.
  • Duplex: simplex (one way), half-duplex (one way at a time, like a walkie-talkie), full-duplex (both at once, modern Ethernet).
  • Standards: Ethernet PHYs like 10BASE-T, 100BASE-TX, 1000BASE-T, 10GBASE-T; Wi-Fi 802.11 a/b/g/n/ac/ax.
  • Devices: hubs, repeaters, cables, modems, media converters, the physical part of a NIC.
  • Data unit: Bits.

Addressing: MAC vs IP vs port

Three different addresses do three different jobs — don't mix them up:

  • MAC address (Layer 2) — fixed on the network card. Only works on the local link.
  • IP address (Layer 3) — logical address used to route across networks.
  • Port number (Layer 4) — picks which program on the machine.

Analogy: IP = the building's street address, MAC = which mailbox on the local floor, Port = which person inside the office.

Network devices by layer

DeviceLayerWhat it does
Hub / repeater1Copies the signal to every port. No brains.
NIC (network card)1–2Connects a device; holds the MAC address.
Switch2Forwards frames by MAC; learns a MAC-to-port table.
Access point2Bridges Wi-Fi devices onto the wired network.
Router3Forwards packets between networks using IP.
Layer-3 switch2 + 3Switching and routing in one box.
Firewall3–4Filters by IP and port (next-gen ones go up to L7).
Load balancer4 or 7Spreads traffic across servers.
Proxy / WAF7Reads and filters application traffic.

Protocols by layer (reference)

LayerProtocols
7 ApplicationHTTP, HTTPS, DNS, SMTP, IMAP, POP3, FTP, SFTP, TFTP, SSH, Telnet, DHCP, SNMP, NTP, LDAP, RDP, SMB, NFS
6 PresentationTLS/SSL, MIME, ASN.1; formats JPEG, PNG, MP3; encodings ASCII, UTF-8
5 SessionSockets, RPC, NetBIOS, PPTP, L2TP
4 TransportTCP, UDP, QUIC, SCTP
3 NetworkIP (v4/v6), ICMP, IPsec, OSPF, BGP, RIP, EIGRP
2 Data LinkEthernet, Wi-Fi (802.11), PPP, ARP, STP, VLAN (802.1Q)
1 PhysicalEthernet PHY (BASE-T), DSL, USB, Bluetooth, 802.11 radio

(Some protocols don't sit cleanly on one layer — TLS, ARP, and MPLS are the usual arguments.)

Common port numbers

PortProtocolTransportUse
20 / 21FTPTCPFile transfer (data / control)
22SSH / SFTPTCPSecure shell + file transfer
23TelnetTCPRemote login (plaintext)
25 / 587SMTPTCPSend email
53DNSUDP + TCPName lookups
67 / 68DHCPUDPAuto IP assignment
69TFTPUDPSimple file transfer
80HTTPTCPWeb
110 / 143POP3 / IMAPTCPRead email
123NTPUDPTime sync
161 / 162SNMPUDPDevice monitoring
179BGPTCPInternet routing
389 / 636LDAP / LDAPSTCPDirectory services
443HTTPSTCP (UDP for HTTP/3)Secure web
3389RDPTCPRemote desktop

OSI vs TCP/IP

TCP/IP is the model the internet actually runs on. It's the same idea with fewer layers — it just groups OSI's top three together and (in the 4-layer version) the bottom two:

OSI (7)TCP/IP (4)
7 · 6 · 5 (App, Pres, Session)Application
4 TransportTransport
3 NetworkInternet
2 · 1 (Data Link, Physical)Network Access (Link)

(Textbooks often use a 5-layer version that keeps Data Link and Physical separate.)

Why TCP/IP won (and OSI's limits)

  • TCP/IP was already running (on ARPANET, the early internet) and was free, bundled into Unix. OSI's protocols showed up late, complex, and barely implemented.
  • TCP/IP grew from "rough consensus and running code"; OSI grew from slow committees.
  • OSI's weak spots: the Session and Presentation layers are thin and barely used in practice; it was over-engineered; and several real protocols don't map neatly.
  • So why still learn it? Because it's the shared language. Engineers say "that's a layer 1 problem" (check the cable), "a layer 2 device" (switch), "a layer 7 attack" — OSI is the map everyone reads from.

Troubleshooting by layer

A handy habit: start at the bottom and work up.

  1. L1 Physical — is it plugged in? Cable good? Link light on?
  2. L2 Data Link — right VLAN? MAC/switch port okay? ARP resolving?
  3. L3 Network — can I ping the IP? Right subnet/gateway? Routing okay?
  4. L4 Transport — is the port open? Firewall blocking it?
  5. L5–7 — is the app/service itself up? DNS resolving? Certificate valid?

Security by layer

Most attacks live at one layer. Naming the layer points straight at the fix:

LayerCommon attacksDefenses
1 PhysicalCable taps, Wi-Fi jammingPhysical security, locked ports, encryption
2 Data LinkARP spoofing, MAC flooding, VLAN hoppingDHCP snooping, dynamic ARP inspection, port security
3 NetworkIP spoofing, ICMP/ping floods, SmurfACLs, firewalls, ingress filtering (BCP 38)
4 TransportSYN flood, port scans, session hijackSYN cookies, stateful firewall, rate limiting
5–7Phishing, SQL injection, XSS, DNS poisoning, TLS strippingWAF, input validation, DNSSEC, HSTS, MFA

Quick trick: ask "which layer is this attack at?" and the right device, protocol, and fix usually fall straight out.

Glossary

  • Bit — a single 1 or 0. Byte / octet — 8 bits.
  • Frame / Packet / Segment — the data unit at layers 2 / 3 / 4.
  • Header / Trailer — control info added to the front / back of the data.
  • Payload — the actual data inside, minus the headers.
  • FCS / CRC — an error-check value; if it doesn't match, the frame is dropped.
  • MTU — biggest payload a link carries in one frame (Ethernet = 1500 bytes).
  • MSS — biggest payload TCP puts in one segment (usually 1460 bytes).
  • Bandwidth — max possible data rate. Throughput — actual data rate. Latency — delay. Jitter — variation in delay.
  • Unicast / Broadcast / Multicast — to one / to everyone / to a group.
  • Full / half duplex — both directions at once / one direction at a time.
  • Socket — IP address + port together; one end of a connection.
  • ARP — finds the MAC for an IP on the local network.
  • NAT — many private IPs sharing one public IP.

Related notes