Module 11 · 14 min read · Free chapter
Layering, OSI and TCP/IP, and switching
A network splits its work into layers. OSI has seven: physical, data link, network, transport, session, presentation and application, while TCP/IP has four. Each layer adds a header, so data becomes a segment, packet, frame and bits. Transmission delay is L/R and propagation delay is d/s.
Start from zero: how a letter crosses India
Suppose your aunt in Patna writes a letter to you in Pune. She does not need to know which train carries mail, or how the sorting office works. She writes the letter, puts it in an envelope with the address, and drops it in the post box.
Now look at what happens next. The local post office bundles letters by city, the sorting office puts the Pune bundle on a train, and the train crew only cares about bags, not about what is written inside. In Pune the same steps happen in reverse, and the postman finally hands you the envelope.
Each person in this chain does one job and talks only to the matching person at the other end. Your aunt "talks" to you, the Patna sorting office "talks" to the Pune sorting office, and so on. A computer network works in exactly this way, and each such level of work is called a layer.
Why it matters. Without layers, every program would have to know about cables, radio waves and routes. With layers, a WhatsApp developer writes only the top part, while cable engineers and router makers work on their own parts. That is why the Internet could grow from wires to fibre to 5G without rewriting every application.
Why layers, and the OSI and TCP/IP stacks
A layer is a group of related jobs. Each layer gives a service to the layer above it and uses the service of the layer below it. It also follows a protocol with its peer, the same layer on the other machine, which is a set of rules about message format and order.
The OSI reference model has seven layers. It is mostly used for teaching and for naming things, because the real Internet runs on the simpler TCP/IP stack. From bottom to top the seven layers are as follows.
| No. | Layer | Main job | Example |
|---|---|---|---|
| 7 | Application | Gives network services to user programs | HTTP, SMTP, DNS |
| 6 | Presentation | Data format, encryption, compression | Character code conversion |
| 5 | Session | Starts and ends dialogues, adds checkpoints | Resuming a long transfer |
| 4 | Transport | Process-to-process delivery, reliability, ports | TCP, UDP |
| 3 | Network | Logical addressing and routing across networks | IP, ICMP |
| 2 | Data link | Framing, error detection, access to one link | Ethernet, Wi-Fi |
| 1 | Physical | Sends raw bits as signals on the medium | Cable, fibre, radio |
A common way to remember the order from layer 1 upward is "Please Do Not Throw Sausage Pizza Away". The bottom three layers are present in every router, while the top four run only in the end hosts. That is why transport is called the first end-to-end layer.
The TCP/IP model has four layers: application, transport, internet and link. Many exam papers use a five-layer version in which link is split into data link and physical. There is no separate session or presentation layer, because those jobs, such as encryption, are done by the application itself.
Why it matters. Questions on "which layer does what" appear in almost every RRB JE, IT officer and GATE paper. The real skill is to place a job or a device on the right layer, which the next sections build on.
Encapsulation, PDUs and devices
When you open a web page, the browser creates an HTTP request, which is the message. The transport layer adds a TCP header with port numbers, and the result is a segment. The network layer adds an IP header with source and destination IP addresses, giving a packet (also called an IP datagram).
The data link layer then adds a header with MAC addresses and a trailer with an error check, giving a frame. Finally the physical layer sends the frame as bits, as voltage levels, light pulses or radio waves. This wrapping of data inside headers, layer by layer, is called encapsulation.
At the receiver each layer reads and removes its own header and passes the rest upward, which is decapsulation. The name of the data unit at each layer is its protocol data unit (PDU). So the PDUs are message, segment, packet, frame and bits, from top to bottom.
Network devices are classed by the highest layer they understand. A hub or repeater only copies bits, so it is a physical-layer device, and every machine on a hub shares one collision domain. A switch reads MAC addresses in frames and sends each frame only to the right port, so it is a data-link device that gives each port its own collision domain.
A router opens the frame, reads the IP header, chooses the next hop and builds a new frame for the next link. So a router works at the network layer, and it also separates broadcast domains. A frame's MAC addresses change at every router, but the IP addresses stay the same from source to destination, unless address translation is in use.
Why it matters. Header overhead, MAC versus IP addresses and "what does a router look at" are classic exam questions. For example, if each of four layers adds a 20-byte header to 100 bytes of data, the bits on the wire carry 180 bytes, so only , about 56%, is useful data.
Circuit, packet and virtual-circuit switching
A network has many links and many users, so it must decide how to share them. There are three main ways, and the old telephone network uses the first.
In circuit switching, a path is set up before any data flows, and a fixed share of bandwidth on every link is reserved for that call. Once set up, data flows at a steady rate with no queuing, which suits voice. But the reserved capacity is wasted during silences, and a new call can be refused if no capacity is left.
In packet switching with datagrams, the data is cut into packets, and each packet carries the full destination address. Every router looks up its table separately for each packet, so two packets of the same message may take different paths and arrive out of order. Nothing is reserved, so links are shared well, but delay varies with queues.
Virtual-circuit (VC) switching is a middle path. A setup phase picks a route and stores a small VC number in each router on it. After that every packet carries only the VC number, follows the same route and arrives in order, but bandwidth is still shared, not reserved.
| Feature | Circuit | Datagram | Virtual circuit |
|---|---|---|---|
| Setup phase | Yes | No | Yes |
| Address in each packet | None needed | Full destination address | Short VC number |
| Path | Fixed | Each packet decides | Fixed after setup |
| Order of arrival | In order | May be out of order | In order |
| Bandwidth | Reserved | Shared on demand | Shared on demand |
| Effect of a router failure | Call drops | Packets reroute | Circuit must be set up again |
The Internet's IP layer is a datagram network. Older networks such as X.25, Frame Relay and ATM used virtual circuits. There was also message switching, where a whole message was stored and forwarded at each node, but it is now only of historical interest.
Why it matters. Packet switching lets many bursty users share a link, which is why the Internet is cheap. For example, a 10 Mbps link can carry ten users who each need 1 Mbps under circuit switching. With packet switching it can serve far more than ten such users if each is active only part of the time, since they rarely all send together.
The four delays and store-and-forward numericals
A packet going through one router faces four delays. Processing delay is the time to check the header and look up the route, usually microseconds. Queuing delay is the wait behind other packets, which can be zero or very large.
Transmission delay is the time to push all bits of the packet onto the link, equal to for L bits on a link of R bits per second. Propagation delay is the time for one bit to travel the length of the link, equal to for distance d and signal speed s. In copper and fibre s is about 2 × 10⁸ m/s, two-thirds of the speed of light in vacuum.
Students often mix the last two, so think of a toll booth. The time for a whole bus convoy to pass the booth is transmission, and it depends on how many buses there are and how fast the booth works. The time for one bus to drive to the next town is propagation, and it depends only on the distance.
Worked example 1. A 1,000-byte packet is sent on a 1 Mbps link that is 2,000 km long.
- The packet has 8,000 bits, so the transmission delay is s = 8 ms.
- The propagation delay is = 10 ms.
- With no processing or queuing, the last bit reaches the far end after ms.
Store-and-forward. A router must receive the whole packet before it can send it on. So one packet over N equal links takes of transmission time, plus the propagation on each link.
Worked example 2. A 10⁶-bit file goes over 3 links of 1 Mbps each, through 2 routers, ignoring propagation.
- Sent as one message, each link needs 1 s, so the total is s.
- Cut into 1,000 packets of 1,000 bits, each packet needs 1 ms per link.
- The first packet arrives after 3 ms, and then one packet arrives every 1 ms, so the total is , about 1 s.
Small packets win because all links work at the same time, like an assembly line. The general rule is for P packets over N links. In practice each packet also carries a header, so packets that are too small waste bandwidth on headers.
Queuing and traffic intensity. If packets of L bits arrive at an average rate of a packets per second, the traffic intensity is . If it is above 1, bits arrive faster than they can leave and the queue grows without limit. Even below 1, the average queuing delay rises very sharply as the intensity gets close to 1.
Why it matters. GATE often asks for total delay over several hops, or the best packet size for a file. Every such question is solved by writing transmission and propagation separately for each link and then adding carefully.
Bandwidth-delay product, RTT and throughput
Imagine the link as a water pipe. Its width is the bandwidth R and its length, in time, is the propagation delay. The amount of water that fills the pipe is the bandwidth-delay product, R × propagation delay, measured in bits.
Worked example 3. A 100 Mbps link has a one-way propagation delay of 20 ms.
- The bandwidth-delay product is bits, which is 250 KB.
- So when the first bit reaches the receiver, bits are already on the wire behind it.
- If the sender must wait for a reply before sending more, it should be allowed to send about twice this amount, one RTT's worth, to keep the pipe full.
The round-trip time (RTT) is the time for a small packet to reach the other end and for the reply to come back. When transmission and queuing are small, RTT is about twice the one-way propagation delay. In the example above, RTT is about 40 ms.
Throughput is the rate at which useful data actually reaches the receiver. On a path of several links it is limited by the slowest link, called the bottleneck. For example, a file going through links of 100 Mbps, 10 Mbps and 50 Mbps gets at most 10 Mbps.
This product explains why fast long-distance links are hard to use well. A sender that sends one frame and then waits for an acknowledgement wastes most of the pipe, and sliding-window protocols fix this by keeping many frames in flight. The same idea sets the TCP window size needed on a fast path.
Why it matters. The bandwidth-delay product is the hidden link between this chapter and the efficiency numericals of the data link and transport layers. If you can find it quickly, window-size and efficiency questions become one-liners.
Descriptive lens: how written papers ask this
Written papers for IT officer posts, state Assistant Programmer exams and university-level tests ask about layering and switching in four ways:
- Explain the OSI model layer by layer, with the job and one protocol or device for each layer.
- Compare the OSI and TCP/IP models, usually in a table, and say why TCP/IP won in practice.
- Contrast circuit, datagram and virtual-circuit switching with their advantages and drawbacks.
- Calculate end-to-end delay for a given path and packet size, and comment on the result.
Practice questions (our own, not previous-year questions).
- What is layering in computer networks? Explain the seven layers of the OSI model with one example for each layer. (10 marks)
- Compare circuit switching and packet switching, and explain why the Internet uses packet switching. (10 marks)
- A 4 MB file is sent over 4 links of 10 Mbps each, using packets of 10,000 bits. Find the total transfer time ignoring propagation, and explain what would happen with much smaller packets. (15 marks)
Answer plan for question 2.
- Begin by defining circuit switching as reserving a path and bandwidth for the whole call after a setup phase.
- Then define packet switching as sending independent packets that share links on demand without any reservation.
- Draw a comparison table covering setup, use of bandwidth, delay, order of arrival and the effect of failures.
- Explain that circuit switching wastes reserved capacity during silences, which is costly for bursty computer traffic.
- Show with a small example that packet switching lets many more bursty users share one link.
- Conclude that the Internet chose packet switching because data traffic is bursty and robustness matters more than fixed delay.
Quick revision
- A layer gives a service to the layer above and talks to its peer layer through a protocol.
- The OSI layers from the bottom are physical, data link, network, transport, session, presentation and application.
- In practice the Internet's TCP/IP model has four layers, application, transport, internet and link, and five in the teaching version.
- The PDUs from the top are message, segment, packet, frame and bits.
- A hub works at layer 1, a switch at layer 2 and a router at layer 3.
- Circuit switching reserves bandwidth, datagrams carry full addresses, and virtual circuits fix the path without reserving bandwidth.
- Transmission delay is and propagation delay is .
- P packets over N store-and-forward links take plus propagation.
- The bandwidth-delay product R × propagation delay is the number of bits in flight on a link.
- The slowest link on a path sets its throughput.