Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 2: The OSI Model and TCP/IP Model

2.2 The seven layers

Now let's look at the seven layers one by one. When Mauli Dairy's order page reaches your browser, the data goes from top to bottom on the sender's side and comes back from bottom to top on the receiver's side – this is called encapsulation and decapsulation.

   Sender                                                    Receiver
 +------------------+        (logical communication)      +------------------+
 | 7 Application    | <---------------------------------> | 7 Application    |
 | 6 Presentation   | <---------------------------------> | 6 Presentation   |
 | 5 Session        | <---------------------------------> | 5 Session        |
 | 4 Transport      | <------------ segments -----------> | 4 Transport      |
 | 3 Network        | <------------ packets ------------> | 3 Network        |
 | 2 Data Link      | <------------ frames -------------> | 2 Data Link      |
 | 1 Physical       | ============== bits ==============  | 1 Physical       |
 +------------------+     cable / fibre / radio           +------------------+
   Data goes DOWN the stack (encapsulation) and UP at the receiver (decapsulation)
# Layer Main function Protocols / standards Devices Data unit (PDU)
7 Application Interface for user applications; network services HTTP, HTTPS, FTP, SMTP, DNS, SSH, DHCP, SNMP Gateways, L7 load balancers (AWS ALB), WAF Data / message
6 Presentation Translation, encryption, compression, data format TLS/SSL, JPEG, PNG, ASCII, UTF-8, MPEG — Data
5 Session Establish, maintain, terminate sessions; checkpoints NetBIOS, RPC, SQL session, PPTP — Data
4 Transport End-to-end delivery, ports, segmentation, flow & error control TCP, UDP L4 load balancers (AWS NLB), firewalls Segment (TCP) / Datagram (UDP)
3 Network Logical addressing (IP), routing between networks IPv4, IPv6, ICMP, ARP*, OSPF, BGP Router, L3 switch Packet
2 Data Link Physical (MAC) addressing, framing, error detection on a link Ethernet (802.3), Wi-Fi (802.11), PPP, VLAN (802.1Q) Switch, bridge, NIC Frame
1 Physical Transmission of raw bits over the medium; voltages, connectors RJ-45, fibre, DSL, Bluetooth radio, 802.11 PHY Hub, repeater, cables, modem Bit

* ARP works between Layer 2 and 3 (it maps IP → MAC), so books place it in either.

Layer-by-layer in simple words

  • Layer 7 – Application: What the user's program speaks. The browser speaks HTTP; ssh speaks the SSH protocol. Not the application itself (Chrome), but the protocol it uses.
  • Layer 6 – Presentation: Makes data understandable to both sides — character encoding (UTF-8), compression (gzip) and encryption (TLS). HTTPS = HTTP + TLS.
  • Layer 5 – Session: Opens, manages and closes a conversation (session). E.g. keeping you logged in, resuming a large download.
  • Layer 4 – Transport: Adds source and destination port numbers. TCP is reliable (3-way handshake, acknowledgements, retransmission, ordering) — used by HTTP, SSH, MySQL. UDP is fast and connectionless — used by DNS, video calls, online games.
  • Layer 3 – Network: Adds source and destination IP addresses and chooses the path (routing). Routers work here. ping (ICMP) tests this layer.
  • Layer 2 – Data Link: Adds MAC addresses (48-bit hardware address like 0a:1b:2c:3d:4e:5f) to move frames within one local network. Switches work here.
  • Layer 1 – Physical: Converts frames into electrical signals, light pulses or radio waves.

TCP vs UDP

Students in my class ask: "If TCP is reliable, why isn't it used everywhere?" Look – reliability has a cost (handshakes, acknowledgements, retransmissions). For a small DNS query or a live video call, speed matters more than perfection.

Feature TCP UDP
Connection Connection-oriented (3-way handshake SYN, SYN-ACK, ACK) Connectionless
Reliability Guaranteed delivery, ordering, retransmission Best effort; may lose packets
Speed / overhead Slower, 20-byte header Faster, 8-byte header
Uses Web (HTTP/1.1, HTTP/2), SSH, e-mail, databases DNS, DHCP, VoIP, streaming, gaming, HTTP/3 (QUIC)

Encapsulation

As data moves down, each layer adds its own header (Layer 2 also adds a trailer):

 L7-5   [                 HTTP data                   ]
 L4     [TCP hdr: ports ][        HTTP data           ]            = Segment
 L3     [IP hdr: IPs][TCP hdr][      HTTP data        ]            = Packet
 L2     [Eth hdr: MACs][IP][TCP][    HTTP data   ][FCS]            = Frame
 L1     0101100101110100101010010101001010101010101...            = Bits

Think of encapsulation as a box inside a box: the HTTP data goes into a TCP header box, that goes into an IP header box, and that goes into an Ethernet header box. The receiver opens the boxes one by one in reverse order – this is called decapsulation.

Ravindra Bagale's Tip

In interviews many students say "a switch works at Layer 3". Remember: a normal switch works at Layer 2 (MAC addresses), a router at Layer 3 (IP). And HTTPS is not a separate layer – HTTP (L7) runs over TLS (L6). Pay attention!

Lab

Tumchya Linux machine var ip addr chalva aani link/ether samor MAC address (L2) aani inet samor IP address (L3) shodha. Mag ek chhota table banva: layer, address cha prakar aani tumcha value.