Study Guide

Packets and Packet Switching

Why data is broken into small packets before it crosses a network, what each packet carries, and how routers send the packets by different routes so that the receiving device can put them back in order.

Lesson 4.1 Networks, the Internet and Security

For: Cambridge IGCSE Computer Science learners, or anyone who has sent a message or a file over the internet and wonders how it gets there

Stage: Think

A book that will not fit in one envelope

A pupil, Maya, wants to post a 300-page printed story to a friend, Daniel, who lives in another town. The post office is fictional, but it works like a real one. Its envelopes hold at most 50 pages each, and the envelopes are carried by different vans, so they will not necessarily arrive on the same day or in the same order.

Think it through

Maya splits the story into six envelopes. What should she write or include so that Daniel can put the story back together correctly?

Show a model answer

Each envelope needs Daniel’s address, so the post office can deliver it. Each needs a number (“envelope 3 of 6”), so Daniel can put the pages in order and notice if one is missing. It is also sensible to write Maya’s own address on each one, so that it can be returned or Daniel can reply.

Stage: Discover

The same idea on a network

A network works in the same way. A photo, a message or a web page is far too long to be sent in one piece, so the sending device breaks the data into small pieces. Each piece is wrapped with the information that Maya wrote on her envelopes.

A small piece of data, sent with information about where it is going and where it fits, is called a packet. The information at the front of a packet is its packet header. The header holds three things:

  • the destination address: the address of the device the packet is going to;
  • the packet number: where this packet fits in the whole message, for example 3 of 6;
  • the originator’s address: the address of the device that sent it.

Check your understanding

Six packets of a photo reach a phone in a different order from the one in which they were sent. Which part of the header lets the phone put them in the right order?
Show the answer

Answer: B. The packet number, because it shows where each packet fits in the whole photo.

The packet number is the only header item that differs between packets of the same message. The two addresses are the same on every packet of that message.

Stage: Explain

What is inside, and what ends the packet

Think it through

A packet cannot be only a header: the header is just the label on the envelope. What else must a packet contain? And what might be useful at the very end of a packet?

Show a model answer

It must contain the actual data: Maya’s 50 pages. At the end, something that marks the end of the packet, and ideally something Daniel can use to check that the contents arrived undamaged.

The data that the packet carries, a slice of the photo or the message, is the payload. The part at the end is the trailer. It marks the end of the packet and usually carries information the receiving device uses to check whether the packet was damaged on the way. How such a check works is the subject of the lesson Error Detection.

So a packet is made of three parts, always in this order:

PartWhat it holds
HeaderDestination address, packet number, originator’s address
PayloadA slice of the data being sent
TrailerThe end of the packet, and information for checking it

Only the payload is the data the user wanted. The header and the trailer are extra information that the network needs to deliver it.

Which part of the packet?
ItemHeader, payload or trailer?
The address of the device that should receive the packet
A 1,000-byte slice of a photo
“Packet 4 of 9”
The address of the laptop that sent the packet
A marker showing that the packet has ended

    Show the completed table
    ItemHeader, payload or trailer?
    The address of the device that should receive the packetheader
    A 1,000-byte slice of a photopayload
    “Packet 4 of 9”header
    The address of the laptop that sent the packetheader
    A marker showing that the packet has endedtrailer

    Stage: Predict

    Many roads between two towns

    Daniel and Maya’s towns are joined by several roads. The vans do not all take the same road: the post office sends each one by whichever road is clear when it is ready to leave. On a network, the junctions are routers, and a packet is passed from one router to the next until it reaches its destination.

    Think it through

    Six packets leave a laptop in order 1, 2, 3, 4, 5, 6, and the routers send them along different roads. Will they necessarily arrive in the order 1 to 6? Explain what might change the order.

    Show what happens

    No. A packet sent early could take a slow, busy road and arrive after a packet sent later by a quicker road. So the arrival order can be mixed up, even though the sending order was 1 to 6.

    Sending each packet separately, with every router choosing the next step for it, is called packet switching. A router is a device that receives packets and sends each one onwards towards its destination. It reads the destination address in the packet header, then chooses the next router on the way, usually by a route that is quick and not busy at that moment.

    Two packets of the same message can be sent by different routes. The route is not fixed in advance: the router controls it, one step at a time.

    Stage: Experiment

    Watching four packets travel

    Ravi, at a fictional school, uploads a short file to a library server. The file is split into four packets. Step through what happens. Between the school and the library there are four routers: A (the school’s), B, C and D (the library’s). B and C are two different roads between A and D.

    A four-packet file travels from Ravi’s laptop to the library server

    Each step names the device that acts. Watch which router chooses the route, and in which order the packets arrive.

    1. Ravi’s laptop

      Step 1 of 6: The file is broken into four packets

      Each packet gets a header: the library server’s address as the destination, the laptop’s address as the originator’s address, and a packet number from 1 to 4 (“of 4”). Each also gets a trailer. The laptop sends them to Router A.

    2. Router A

      Step 2 of 6: Packet 1 is sent by Router B

      Router A reads the destination address in packet 1. The road through Router B is quiet, so A passes the packet to B.

    3. Router A

      Step 3 of 6: Packet 2 is sent by Router C

      By the time packet 2 arrives, the road through B is busy, so Router A chooses the road through Router C instead. Packets 1 and 2 are on different routes.

    4. Routers B and C

      Step 4 of 6: Each router passes its packet on to Router D

      Router B passes packet 1 to D, and Router C passes packet 2 to D. Packets 3 and 4 follow: A sends 3 through C, which has become slow, and 4 through B, which has cleared.

    5. The library server

      Step 5 of 6: The packets arrive in a different order

      Packet 4 arrives before packet 3, because it took the quicker road. The arrival order is 1, 2, 4, 3.

    6. The library server

      Step 6 of 6: The packets are put back in order

      The server waits until the last packet has arrived, and checks that it has all four. It then uses the packet numbers to put the payloads in order 1, 2, 3, 4. The original file is rebuilt.

    Check your understanding

    In the example, the server has packets 1, 2 and 4, and packet 3 is still on its way. What does the server do?
    Show the answer

    Answer: C. It waits for the last packet, then orders the payloads by packet number.

    The receiving device waits until the last packet has arrived, then uses the packet numbers to reorder the packets.

    A packet does not carry a map of its journey, and the sender does not plan the whole route. Each router reads only the destination address in the header and decides the next step using what it knows of the network at that moment. That is why packets of one message can take different routes.

    Stage: Apply

    Rebuilding a message

    Before you do one yourself, here is how a receiving device rebuilds a message, and why each step is taken.

    A short text is sent in six packets. They arrive in this order, each with its packet number: 3 (“the”), 1 (“Meet”), 5 (“gate”), 2 (“at”), 6 (“tonight”), 4 (“main”).

    1. Wait until the last packet has arrived. All six packet numbers, 1 to 6, are now here. Rebuilding earlier could leave a piece out.
    2. Read the packet number in each header. The numbers, not the arrival order, say where each payload fits.
    3. Sort the packets by number, smallest first. Packet 1 is “Meet”, then 2 “at”, 3 “the”, 4 “main”, 5 “gate”, 6 “tonight”.
    4. Join the payloads in that order. The message is “Meet at the main gate tonight”.

    Now do the same. Five packets of another message arrive in the order 4, 1, 3, 5, 2. Each has its packet number and payload.

    ArrivedPacket numberPayload
    first4five
    second1Library
    third3at
    fourth5today
    fifth2closes
    Rebuild the message, in packet-number order
    Packet numberPayload
    1
    2
    3
    4
    5

      Show the completed table
      Packet numberPayload
      1Library
      2closes
      3at
      4five
      5today

      Apply it

      Priya says: “All the packets of one file must take the same route. If they took different routes, the file would arrive scrambled.” What is wrong with Priya’s reasoning?
      Show the answer

      Answer: C. Packets may take different routes; the packet numbers let the receiver rebuild the file in order.

      Packet numbers are what make different routes safe: the receiver does not depend on the arrival order.

      Stage: Consolidate

      Why use packets at all?

      Think it through

      Give one advantage and one disadvantage of splitting data into packets and sending them by different routes. Think about a broken router, a damaged piece of data and the extra information on every packet.

      Show a model answer

      Advantages: if a router fails or a road is busy, later packets can go another way, so the message still gets through; if one packet is damaged, only that packet has to be sent again, not the whole file. Disadvantages: the packets may arrive out of order and have to be put back, which takes time; every packet carries a header and a trailer, which is extra data to send.

      Apply it

      A video message is sent in 400 packets. Packet 212 is damaged on the way, and the other 399 arrive safely. Which statement about packet switching explains why this is not a disaster?
      Show the answer

      Answer: A. Only packet 212 needs to be sent again, because each packet has its own number.

      The packet number identifies the damaged piece, so only that packet is sent again.

      Think it through

      In your own words, explain to someone who has not done this lesson how a photo gets from one phone to another across the internet. Use the words packet, header, payload, router and packet number.

      Show a model answer

      A good answer: “The sending phone breaks the photo into packets. Each packet has a header with the destination address, the sender’s address and a packet number, a payload that is a slice of the photo, and a trailer. Routers read the destination address and pass each packet on, possibly by different routes. The receiving phone waits until the last packet has arrived and uses the packet numbers to put the payloads in order.”

      • Data is broken into packets before it is sent. Each packet has a header (destination address, packet number, originator’s address), a payload (a slice of the data) and a trailer (the end of the packet and information for checking it).
      • In packet switching, each packet may take a different route. A router controls the route by reading the destination address and choosing the next step.
      • Packets may arrive out of order. Once the last packet has arrived, the receiver uses the packet numbers to put them in order.
      • Splitting data into packets means only a damaged packet has to be sent again, and traffic can go round a busy or broken router. The cost is extra header data on every packet, and the work of reordering.
      Go deeper Packet switching and circuit switching

      Older telephone networks used circuit switching: a line was set aside between the two callers for the whole call, and nobody else could use it, even during silences. Packet switching shares the network: many conversations send packets along the same roads. Sharing wastes less capacity, but packets can arrive late and out of order, which is why packet numbers matter. Comparing the two methods in detail is part of the A Level course, not this lesson.

      Sources and scope

      • What this lesson is. The first lesson of the Networks, the Internet and Security module, written for this site. Its curriculum links are provisional: the wording of each linked specification point has been checked against the published specification, but no link has been verified by the site owner, and the links imply no endorsement by any examination board.
      • Original material. Maya’s envelopes and the post office, Ravi’s upload to the library server, the four routers, the two short messages and Priya’s claim are fictional examples written for this lesson. The post office comparison is an analogy: real packets are electrical or radio signals, not paper.
      • Simplified on purpose. Real packet headers hold more than three items, and real packets are of limited size set by the network (a typical limit is about 1,500 bytes). Routers choose routes using tables and measurements that are not explained here. The lesson does not name the protocols that do the work. How a lost or damaged packet is detected and sent again is taught in Error Detection. Circuit switching is left to the A Level course.