AP Computer Science Principles · Unit 4 lecture · Part 2 of 11 · 6 min

4.1 BandwidthHow much data per second

Mr. Thompkins
Here's the one calculation in Topic 4.1, and it has one trap that catches half the class: bits versus bytes. Get that right and these questions are free points.

Bandwidth is the maximum amount of data that can be sent in a fixed amount of time. It is usually measured in bits per second, and since that number gets big fast, you'll see megabits per second (Mbps) and gigabits per second (Gbps). Think of bandwidth as the width of a pipe. A wider pipe moves more water per second; it doesn't make the pipe any shorter.

?Wait, what's the difference between a bit and a byte?
A bit is a single binary digit, a 0 or a 1, from Unit 2. A byte is 8 bits. Network speeds are measured in bits per second, but file sizes are usually given in bytes, so you multiply bytes by 8 to get bits before dividing by the bandwidth.

The time to send a file, ignoring other delays, is its size in bits divided by the bandwidth. A 50 megabyte (MB) file is 50 × 8 = 400 megabits. At 10 Mbps it takes 400 ÷ 10 = 40 seconds. At 100 Mbps it takes 4 seconds. Ten times the bandwidth, one tenth of the time.

Seconds to send a 50 MB file4010 Mbps1625 Mbps850 Mbps4100 Mbps
The same 50 MB file (400 megabits) at four bandwidths. Doubling the bandwidth halves the time.

Bandwidth is not the same as latency. Latency is how long it takes one piece of data to make the trip, usually measured in milliseconds. A connection can have huge bandwidth and still feel laggy in a game if each trip is slow, for example when the signal goes up to a satellite and back. The CED defines bandwidth; latency is a word you need only so you don't confuse the two.

wide pipehigh bandwidthnarrow pipelow bandwidthlatency: how long one trip takesbandwidth: how much data per secondmeasured in bits per second
Bandwidth is the width of the pipe: how much data can flow each second. Latency is its length: how long one piece takes to arrive.
?Wait, how does compression fit in?
Lossless and lossy compression from Unit 2 make a file smaller. A smaller file has fewer bits to send, so it arrives sooner over the same bandwidth. Streaming services compress video heavily for exactly that reason.
Pause and think
Your family's internet plan goes from 50 Mbps to 200 Mbps. Predict what happens to the time to download a big game update. Does a video call that already worked smoothly get four times better?
I thought about it. Show me
The download takes about a quarter as long, because the same number of bits flows four times as fast. The video call probably looks about the same: it only needed a few Mbps to begin with, and if it had lag, that was latency, which more bandwidth does not fix.
Compute a transfer time
A game update is 2 GB. (1 GB = 1,000 MB.) How long does it take to download at 50 Mbps? And how much bandwidth would you need to finish it in 80 seconds?
  1. Convert to megabytes: 2 GB = 2,000 MB.
  2. Convert bytes to bits: 2,000 × 8 = 16,000 megabits.
    Why?
    The bandwidth is in megabits per second, so the size has to be in megabits too. This is the step people skip.
  3. Divide by the bandwidth: 16,000 ÷ 50 = 320 seconds, which is 5 minutes 20 seconds.
  4. For 80 seconds, flip it around: bandwidth = bits ÷ time = 16,000 ÷ 80 = 200 Mbps.
    Why?
    Same relationship, solved for a different quantity. Check that it makes sense: a quarter of the time needs four times the bandwidth, and 4 × 50 = 200.

Answer: 320 seconds (5 minutes 20 seconds) at 50 Mbps. To finish in 80 seconds you need 200 Mbps.

Stuck? Get a hint
  1. Get everything into megabits first.
  2. 2 GB is 2,000 MB, and each byte is 8 bits.
  3. Time = 16,000 megabits ÷ 50 megabits per second.
Check yourself
A 15 MB photo album is uploaded over a connection with an upload bandwidth of 6 Mbps. Ignoring other delays, about how long does it take?
  1. A2.5 seconds
  2. B20 seconds
  3. C90 seconds
  4. D0.4 seconds
Show the answer

B. 15 MB is 15 × 8 = 120 megabits, and 120 ÷ 6 = 20 seconds. The top trap is 2.5 seconds, which divides 15 by 6 without turning bytes into bits. 90 multiplies when it should divide.

Exam tip from Mr. T

When a question gives a file in bytes and a speed in bits per second, write "× 8" in the margin before you do anything else. And sanity check the direction: more bandwidth must mean less time.

  • Bandwidth: the maximum data sent in a fixed time, measured in bits per second.
  • Transfer time ≈ size in bits ÷ bandwidth. Multiply bytes by 8 first.
  • Latency is the time for one trip. More bandwidth does not shrink latency.