Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 79 ยท Getting Started with Networks

How Data Travels: Packets and Switching

See how data crosses a network: circuit versus packet switching, store-and-forward routers, statistical multiplexing and the anatomy of a packet, with live code.

When you send a photo to a friend, the photo does not travel as one object down a private pipe. It is cut into many small pieces, each piece is labeled with where it should go, and the pieces are handed from device to device until they arrive and are put back together. This design is called packet switching, and it is the core idea behind the Internet.

To appreciate why it won, this lesson compares it with the older approach used by telephone networks, circuit switching. You will see how a router forwards a packet, why cutting a message into pieces makes it arrive sooner, how many users can share one link, and what a packet looks like on the inside. It builds on What Is a Computer Network? and leads into performance.

Circuit switching

In a circuit-switched network, the network first sets up a dedicated path between the two ends, then the conversation uses it, then the path is torn down. The classic example is a phone call: the call is placed, switches along the way reserve capacity, and for the whole call that capacity belongs to you, even during silence.

Advantages: once the circuit exists, delay is small and constant, and the quality is guaranteed. Drawbacks: setting it up takes time, and reserved capacity is wasted whenever you are quiet. If a link can carry 10 reserved circuits, the 11th caller is simply refused, even if the other ten are sitting in silence.

Data traffic is the opposite of a steady phone call. A browser sits idle while you read, then bursts to fetch a page. Reserving capacity for bursty traffic wastes most of it.

Packet switching

In a packet-switched network, no path is reserved. The sender cuts the data into packets and each one is sent separately, carrying its own addressing information. Every router looks at the destination address of each arriving packet and forwards it toward the next hop. Packets of many different conversations share the same links, one after another, whenever the link is free.

flowchart LR
  H1["Sender"] -->|"packets 1, 2, 3"| R1["Router 1"]
  R1 --> R2["Router 2"]
  R1 --> R3["Router 3"]
  R2 --> R4["Router 4"]
  R3 --> R4
  R4 -->|"packets arrive"| H2["Receiver"]

Packets of one message may take different paths and need not arrive in order.

Because nothing is reserved, there is no setup time and no wasted idle capacity. The price: packets can wait in line when a link is busy, so delay varies, and if the waiting line overflows, packets are dropped. Later layers (mostly TCP) repair these problems for applications that need reliability.

Store-and-forward

A router does not start sending the first bits of a packet before the last bits have arrived. It first receives the whole packet, checks it, finds the right outgoing link, and then transmits it. This behavior is called store-and-forward.

Consequently, a packet of L bits on a link with rate R bits per second needs L / R seconds to be pushed onto each link, and it must be fully received before the next hop can begin. Over N links in a row with a single packet, the transmission time adds up to N ร— L / R. (This ignores the time a signal needs to travel through the cable, called propagation delay, and any waiting in queues. The next lesson covers all delay types.)

This has a surprising consequence. Sending one huge message in a single packet over three links takes three full message-times. But if you split it into many small packets, the packets can be in different hops at the same time, like cars on a highway, so the total time falls to almost one message-time. With P equal packets of L bits each over N links, the time is (N + P โˆ’ 1) ร— L / R: the first packet needs N packet-times to arrive and each further packet arrives one packet-time later.

Python Why splitting a message helps

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

One packet takes 2.4 s. Cutting the same file into 800,000-bit packets drops that to 0.96 s, and with 12,000-bit packets (1,500 bytes, the size of a full Ethernet payload) it is 0.803 s, close to the 0.8 s that a single link would need. Smaller packets help, but each packet carries a header, so making them too small wastes capacity on overhead. Real networks settle on packets of roughly 1,500 bytes or less.

Statistical multiplexing

Why is sharing a link efficient? Suppose a 1 Mbit/s link serves users who each need 100 kbit/s while active, but each user is active only 10% of the time. With circuit switching you can reserve for exactly 10 users. With packet switching you can let many more users share the link, because it is unlikely that more than 10 are active at once. This idea, giving capacity on demand to whoever has data right now, is called statistical multiplexing.

The chance that more than 10 users are active simultaneously follows the binomial distribution. The simulation below computes it exactly.

Python How many users can share a link?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With 35 users, the link is overloaded for about 0.04% of the time, so packet switching serves 3.5 times as many users as circuits, at almost no visible cost. With 50 users the overload chance is 0.9%. During overload packets queue briefly (or are dropped); on average everyone still gets a good service. The trade-off is clear: packet switching gives better use of capacity, circuit switching gives guarantees. That is why today's phone calls themselves often travel as packets (voice over IP), with extra mechanisms to keep delay low.

Anatomy of a packet

Every packet has two parts.

  • The header holds the control information the network needs: the source and destination addresses, the length, a protocol number, error-checking bits and so on.
  • The payload is the actual data being carried, often a piece of a bigger message.

Some protocols also add a trailer after the payload, for example a checksum at the end of an Ethernet frame. As the packet moves through layers, each layer adds its own header around what it received (you will study this in Layered Models).

flowchart LR
  subgraph PKT["One packet"]
    direction LR
    H["Header<br/>addresses, length, protocol"] --- P["Payload<br/>a piece of your data"] --- T["Trailer (optional)<br/>checksum"]
  end

A header says what and where; the payload is the data; some protocols add a trailer.

Different names are used for the same idea at different layers: a frame at the link layer, a packet at the network layer, a segment (TCP) or datagram (UDP) at the transport layer. In casual speech, people say "packet" for all of them.

Message switching and a three-way comparison

Between circuit and packet switching sits a third technique, message switching. There is no path setup, and no cutting: a whole message, with its destination address, is passed from node to node. Each node stores the entire message (often on disk) and forwards it when the next link is free. The telegraph and early store-and-forward mail systems worked this way, and the store-and-forward behavior of email servers still resembles it.

Advantages: no setup, links are shared between many messages, a busy or failed link just delays the message, and the sender need not be online when the receiver is. Drawbacks: each node must have room for the largest message, a long message occupies a link for its whole length so others wait, and every hop re-sends the entire message, so delay is the full transmission time multiplied by the hop count. Interactive use (voice, a web click) is impossible. Splitting messages into small packets removes the last two problems, and that step turned message switching into packet switching.

Circuit switching Message switching Packet switching
Path setup Yes, before data No No (datagram) or yes (virtual circuit)
Unit of transfer Continuous stream Whole message Small packets
Resources Reserved for the call Shared Shared
Delay Setup, then constant High, grows with message size and hops Low for large data, varies with queues
Bandwidth use Wasted when idle Good Good
Buffering at nodes None Whole message One packet
Example Telephone call Telegram, store-and-forward mail The Internet

The next example puts numbers on the three approaches for one file crossing four links.

Python Circuit, message and packet switching compared

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Message switching needs hops ร— message time, the same formula as the store-and-forward example above with a single giant packet. Packets pipeline through the links, so smaller packets get close to the bare transmission time without any reservation. The price is per-packet headers and queueing delay, which network performance covers.

Datagrams and virtual circuits

Packet-switched networks come in two flavors. In a datagram network (the Internet's IP), each packet carries the full destination address and is routed independently, so two packets of the same message may take different paths. In a virtual-circuit network (older technologies such as X.25, Frame Relay and ATM), a path is set up first and each packet carries a short label identifying it; packets follow the same route, but capacity is still shared. Modern MPLS networks use labels in a similar spirit inside a provider.

What is real and what is a stand-in? The formulas for store-and-forward and for the binomial overload chance are exact for the stated assumptions. A real link has propagation delay, queues, routers that process packets, and users who are not perfectly independent, so real numbers differ. The simulations show the reasoning, not a measurement.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main disadvantage of circuit switching for web browsing?

    Browsing is bursty. A reserved circuit sits unused while you read, and other users cannot borrow its capacity.
  2. 2. A router receives the entire packet before it starts forwarding it. What is this called?

    Store-and-forward means the whole packet is received (and can be checked) before it is transmitted on the next link.
  3. 3. A 2,400,000-bit message crosses 4 links of 1 Mbit/s each as one packet. Ignoring other delays, how long does it take?

    N ร— L / R = 4 ร— 2,400,000 / 1,000,000 = 9.6 s. Splitting it into many packets would cut this a lot.
  4. 4. Which part of a packet carries the destination address?

    Addresses and other control information live in the header; the payload is the data being carried.
  5. 5. What does statistical multiplexing exploit?

    Because users are idle much of the time, a shared link can serve more users than strict reservation would allow.

Summary

  • Circuit switching reserves a dedicated path, giving steady quality but wasting idle capacity.
  • Packet switching cuts data into packets that share links and are forwarded one by one; it uses capacity efficiently but delay varies and packets can be dropped.
  • Routers use store-and-forward: a whole packet is received before it is sent on.
  • Splitting a message into packets lets different packets be in different hops at once; the time is (N + P โˆ’ 1) ร— L / R.
  • Statistical multiplexing lets many bursty users share a link because few are active at once.
  • A packet is a header (control information), a payload (data) and sometimes a trailer; the Internet uses datagram forwarding.
  • Message switching stores and forwards whole messages with no path setup; it is simple but slow and needs big buffers, which is why packet switching cut messages into small pieces.

Next: Bandwidth, Latency, Throughput and Loss.