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.
आता सात लेयर्स एक एक करून बघूया. Mauli Dairy चं ऑर्डर पेज तुमच्या ब्राउझरपर्यंत येतं, तेव्हा डेटा सेंडरकडे वरून खाली जातो आणि रिसीव्हरकडे परत खालून वर येतो – यालाच encapsulation आणि decapsulation म्हणतात.
अब सात लेयर्स एक-एक करके देखते हैं. Mauli Dairy का ऑर्डर पेज आपके ब्राउज़र तक आता है, तब डेटा सेंडर की तरफ़ ऊपर से नीचे जाता है और रिसीवर की तरफ़ वापस नीचे से ऊपर आता है – इसी को encapsulation और 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;
sshspeaks 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.
माझ्या क्लासमध्ये स्टुडंट्स विचारतात: "TCP reliable आहे तर सगळीकडे तेच का वापरत नाहीत?" बघा – reliability ला किंमत आहे (handshakes, acknowledgements, retransmissions). छोट्या DNS query साठी किंवा लाइव्ह व्हिडिओ कॉलसाठी स्पीड परफेक्शनपेक्षा जास्त महत्त्वाचा आहे.
मेरी क्लास में स्टूडेंट्स पूछते हैं: "TCP reliable है तो हर जगह वही क्यों नहीं इस्तेमाल करते?" देखो – reliability की कीमत है (handshakes, acknowledgements, retransmissions). छोटी DNS query के लिए या लाइव वीडियो कॉल के लिए स्पीड परफ़ेक्शन से ज़्यादा ज़रूरी है.
| 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.
Encapsulation ला डब्यात डबा समजा: HTTP डेटाला TCP हेडरचा डबा, त्यावर IP हेडरचा, आणि त्यावर Ethernet हेडरचा. रिसीव्हर उलट क्रमाने एक एक डबा उघडतो – यालाच decapsulation म्हणतात.
Encapsulation को डिब्बे में डिब्बा समझो: HTTP डेटा को TCP हेडर का डिब्बा, उस पर IP हेडर का, और उस पर Ethernet हेडर का. रिसीवर उल्टे क्रम में एक-एक डिब्बा खोलता है – इसी को 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!
Ravindra Bagale's Tip – मराठी
Interview मध्ये बरेच students "switch Layer 3 वर काम करतो" असं सांगतात. लक्षात ठेवा: normal switch Layer 2 (MAC addresses), router Layer 3 (IP). आणि HTTPS वेगळा layer नाही – HTTP (L7) TLS (L6) वर चालतो. ध्यान राखो!
Ravindra Bagale's Tip – हिंदी
Interview में बहुत से students "switch Layer 3 पर काम करता है" बोलते हैं. याद रखो: normal switch Layer 2 (MAC addresses), router Layer 3 (IP). और HTTPS अलग layer नहीं है – HTTP (L7) TLS (L6) पर चलता है. ध्यान रखो!
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.