On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Computational Thinking · Grade 6-8

Bits and Bytes

A bit is a single binary digit (0 or 1), the smallest unit of digital data.

n bits can represent 2n different values

Quick Answer

A bit is a single binary digit (0 or 1), the smallest unit of digital data. A byte is 8 bits, which gives 28=256 patterns, enough for one English letter. Use bits and bytes to answer 'how many values?' and 'how much space?' questions: n bits make 2n patterns, file sizes are counted in bytes (B), and network speeds in bits (b) per second, so you divide a speed by 8 to get bytes per second.

Why This Matters

Bits and bytes let you predict things before they happen: how many photos fit on a phone, how long a download takes, why a color channel stops at 255. The common slip is mixing them up. A 50 Mbps connection moves about 6.25 megabytes a second, not 50, so a 500 MB game takes about 80 seconds to download, not 10.

Intuitive Explanation

One light switch can show two things: off or on. Two switches give four patterns: off-off, off-on, on-off, on-on. Each extra switch doubles the count, because every old pattern now appears once with the new switch off and once with it on. So 3 bits give 8 patterns, 4 bits give 16, and n bits give 2n. Adding one bit does not add one value; it doubles them, so 9 bits give 512 where 8 bits gave 256.

A byte is a group of 8 bits, so it has 28=256 patterns. Read as numbers they run from 0 (00000000) to 255 (11111111), which is why one RGB color channel goes from 0 to 255 and why the letter 'A' fits in one byte as the number 65. Bigger amounts use prefixes: a kilobyte is about a thousand bytes, a megabyte about a million, a gigabyte about a billion. Strictly, the binary versions are 1,024 bytes, 1,048,576 bytes and so on, written KiB and MiB. Computers often report the binary version while drive makers advertise the decimal one, which is why a '500 GB' drive shows up as about 466 GB.

Two look-alike questions need different answers. The binary number 11111111 is worth 255; the number of values 8 bits can hold is 256. One reads a single pattern, the other counts all of them. Watch the capital letter too: lowercase b means bits and uppercase B means bytes, so 8 Mb and 1 MB are the same amount of data.

Think of it like this. Bits behave like coin flips in a row: one flip has 2 outcomes, two flips have 4, ten flips have 1,024, because each new flip doubles every list of results so far. A byte is a row of 8 flips, 256 possible rows. The comparison stops at chance: a computer sets each bit on purpose.

Core idea. All digital data—text, images, music—is ultimately stored as sequences of bits grouped into bytes.


When to Use

Use bits and bytes when a question asks how many different values a number of bits can hold, how much storage something needs, or how fast data moves. Watch the units: b is bits, B is bytes, and Mbps is megabits per second. If the question asks the value of one particular 0/1 pattern, that is Binary. If it asks what a pattern stands for (a letter, a pixel color), that is Data Representation.

Tip. Ask: Is the question how many values some bits can hold, or how much space or speed something needs in bits or bytes?

How to Recognize It

Before calculating with bits and bytes, check what is being measured and which unit, small b or capital B, it uses.

  1. Is the question how many different patterns a number of bits can make?

    Yes means use 2n for n bits. If it asks what one particular pattern of 0s and 1s is worth, that is Binary.

  2. Is a speed given in bits per second while a file size is given in bytes?

    Yes means convert: divide the bit rate by 8 to get bytes per second before you work out a time.

  3. Does the size use KB, MB or GB, or KiB, MiB or GiB?

    Strictly, the first group counts in 1000s and the second in 1024s, though some computers show 1024-based sizes labelled KB, MB or GB. Check which before converting.

  4. Is the question about the drive or memory card itself, rather than an amount of data?

    Yes points to Storage, the drive or card itself. Bits and bytes are only the units you measure its size in.

Bits and Bytes vs Binary vs Data Representation vs Storage

All four come up whenever you talk about data in a computer, and they share the same 0s and 1s. Ask whether you are measuring an amount of data, working out a number, decoding meaning, or talking about the device that keeps it.

Bits and Bytes

Meaning
Bits and bytes are the units for counting data: a bit is one 0 or 1, and a byte is 8 bits.
Key test
You measure amounts of data or count possible patterns.
Formula
n bits⇒2n values
Example
A 10-bit code gives 210=1024 different patterns.

Binary

Meaning
Binary writes a number using only 0 and 1, with each place worth twice the place to its right.
Key test
You work out the number that one pattern stands for.
Formula
value=∑bi⋅2i
Example
Binary 1100 is 8 + 4 = 12.

Data Representation

Meaning
Data representation is the agreed code that turns text, colours or sounds into bits.
Key test
You decode what the bits mean, using a code.
Example
A pixel's colour stored as three bytes, one each for red, green and blue.

Storage

Meaning
Storage is the hardware, such as an SSD or a memory card, that keeps data when the power is off.
Key test
It is a device, measured in bytes but not the same as them.
Example
A 128 GB memory card holding the photos from a camera.

Formula & Notation

n bits can represent 2n different values
A bit holds one of two values: {0,1}. A byte is an ordered 8-tuple of bits: (b7,b6,…,b0) where each bi∈{0,1}, representing the value ∑i=07bi⋅2i.

How to read it: Bits are abbreviated 'b' (lowercase) and bytes are 'B' (uppercase). Storage uses decimal units, KB (kilobyte = 1000 bytes), MB (106 bytes) and GB (109 bytes), and binary units, KiB (kibibyte = 210 = 1024 bytes), MiB (220 bytes) and GiB (230 bytes). Some operating systems show the binary value but label it KB, MB or GB.

Worked Examples

Example 1 — How many bits for 30 ID codes?

Easy

A class of 30 students needs ID codes made of bits, every code different. What is the smallest number of bits that works, and how many codes are left unused?
Show the steps and the answer
  1. Try 4 bits: 24=16 codes.

    Every student needs a different code, so the class needs at least 30 patterns. With 16, students 17 to 30 would have none.

  2. Try 5 bits: 25=32 codes.

    One more bit doubles the patterns from 16 to 32, which covers all 30 students.

  3. Count the spare codes: 32 − 30 = 2.

    Bits only come in whole numbers, so some patterns are usually left over.

  4. Assign codes in order: student 1 gets 00000 and student 30 gets 11101 (29); 11110 and 11111 stay unused.

    Listing the first and last code shows that 5 digits really reach 30 different students.

Answer: 5 bits (25=32 codes), with 2 codes unused.

Takeaway: To label N different things, find the smallest n with 2n≥N.

Example 2 — Number of patterns vs largest value

Standard

One byte has 256 patterns. What is the largest number one byte can store? A game score can reach 1,000. How many bits does the score need, and how many whole bytes?
Show the steps and the answer
  1. List the byte's range: 00000000 is 0 and 11111111 is 255.

    The 256 patterns must also cover 0, so the largest value is 256 − 1 = 255.

  2. Count bits for scores from 0 to 1,000: 29=512 is too few, 210=1024 is enough.

    Scores 0 to 1,000 are 1,001 different numbers, and 1,024 is the first power of 2 that covers them.

  3. Round up to whole bytes: 10 bits needs 2 bytes, which is 16 bits.

    Memory is handed out in whole bytes, so 10 bits takes up the space of 16.

  4. Check the range of 2 bytes: 216=65,536 patterns, values 0 to 65,535.

    The score fits with room to spare, which is why scores are often stored in 2 or 4 bytes.

Answer: One byte stores at most 255. A score up to 1,000 needs 10 bits, so 2 bytes.

Takeaway: n bits give 2n patterns, but the largest value is 2n−1, because one pattern is used for 0.

Example 3 — Find the mistake: megabytes vs megabits

Application

A game download is 600 MB and the internet plan is 40 Mbps. Leo writes: "600 ÷ 40 = 15, so it takes 15 seconds." Find the mistake and correct it.
Show the steps and the answer
  1. Read the units: MB is megabytes, and Mbps is megabits per second.

    Capital B is bytes and lowercase b is bits. Leo divided a size in bytes by a speed in bits, mixing two units.

  2. Convert the file to bits: 600 MB × 8 = 4,800 Mb.

    Each byte is 8 bits, so the file is 8 times bigger when measured in bits.

  3. Divide by the speed: 4,800 Mb ÷ 40 Mb per second = 120 seconds.

    Now both are in megabits, so the megabits cancel and seconds are left.

  4. Compare: 120 seconds is 2 minutes, 8 times Leo's 15 seconds.

    Skipping the factor of 8 always makes a download estimate 8 times too short.

Answer: 4,800 Mb ÷ 40 Mbps = 120 seconds, or 2 minutes, on a connection running at full speed.

Takeaway: Before dividing, put the size and the speed in the same unit: multiply bytes by 8 to get bits.

Where You'll See It

  • Phone photo storage

    A 3 MB (megabyte) photo uses about 3 million bytes, so a phone with 64 GB of free space can hold roughly 20,000 such photos. Bytes are the unit that explains how many photos fit.

  • Internet speed vs. download time

    Your plan says '100 Mbps' (megabits per second) but files are measured in megabytes; since 1 byte = 8 bits, a 100-megabyte file takes about 8 seconds, not 1, because you must divide the bit-rate by 8.

  • One typed letter

    Each character you type, like 'A', fits in one byte (8 bits), which is why a 1,000-character message is roughly 1,000 bytes (1 KB).

Common Mistakes

  1. The slip: Megabits (Mb) and megabytes (MB) are the same thing.

    Why it's tempting: They abbreviate almost identically (lowercase b vs. uppercase B) and both have 'mega', so people treat them as interchangeable.

    Instead: 1 byte = 8 bits. Internet speed is usually in bits (Mbps); file size is in bytes (MB). Divide a bit-rate by 8 to estimate download time in bytes.

  2. The slip: n bits can store n different values.

    Why it's tempting: Counting the bits is easy, so it feels like the count of bits is the count of values.

    Instead: n bits represent 2n values. 8 bits store 28=256 values (0 to 255), not 8 values.

  3. The slip: A kilobyte (KB) and a kibibyte (KiB) are the same size.

    Why it's tempting: Many computers count in 1024s but still label sizes KB, MB and GB, so the two units look like one.

    Instead: A kilobyte is 1000 bytes and a kibibyte is 210=1024 bytes. Drive makers count in 1000s while some operating systems count in 1024s, which is why a 500 GB drive can show as about 466 GB.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. How many different values can 4 bits represent? What about 10 bits?

    Hint: Each extra bit doubles the number of patterns.

  2. How many bits are in 5 bytes? How many bytes are in 64 bits?

    Hint: One byte is a group of 8 bits.

  3. A text message has 160 characters, and each character is stored in 1 byte. How big is the message in bytes and in bits?

    Hint: Find the bytes first, then turn bytes into bits.

  4. An internet plan runs at 80 Mbps (megabits per second). How many seconds does it take to download a 400 MB (megabyte) file?

    Hint: Change megabytes to megabits before you divide.

  5. A question asks what decimal value is stored in the byte 00001010. Is that a bits-and-bytes count, or a binary conversion?

    Hint: Are you counting how many values fit, or reading one value?

  6. A student says: "3 bits can store 3 different values." Correct it by listing every pattern.

    Hint: Start at 000 and count up in binary.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why is a byte 8 bits and not 10?

It was a choice that stuck. Early computers used bytes of different sizes, including 6 and 9 bits. In the 1960s IBM's popular System/360 computers used 8-bit bytes, which was enough for all English letters, digits and symbols with room to spare, and 8 is a power of 2, which suits binary hardware. Other makers followed, and by the 1970s 8 bits was the standard.

What is a nibble?

A nibble is half a byte, 4 bits, and it can hold 24=162^4 = 16 patterns, from 0000 to 1111. It is a handy size because one hexadecimal digit, 0 to 9 or A to F, stands for exactly one nibble, so any byte can be written as two hex digits, such as 3F. The name is a joke: a nibble is a small bite.

Why does my 64 GB phone show less space than that?

Two reasons. The phone may count in 1024s while the box counts in 1000s, so 64 billion bytes can show as about 59.6 GiB. On top of that, the operating system and built-in apps take up several gigabytes before you save anything of your own. Neither one means space is missing; it is being measured or used differently.

How many bits does an emoji take?

More than an English letter. In UTF-8, the most common text code on the web, the letters A to Z take 1 byte each, letters such as é take 2, many Chinese characters take 3, and most single emoji take 4 bytes, which is 32 bits. That is why a message full of emoji uses more space than one of the same length in plain English letters.

Learning Path

← Before

Binary
Bits and Bytes

You are here

You need Binary first: digits 0 and 1 and place values that double. Bits and Bytes adds counting: n bits give 2n patterns, 8 bits make a byte, and units like KB, MB and GB measure files. Next, Data Representation decides what the patterns mean, Storage looks at where bytes are kept, and Data Compression stores the same information in fewer of them.

See Also