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

Data Representation

The way information—numbers, text, images, and sound—is encoded as binary digits (0s and 1s) inside a computer.

E:D→{0,1}∗

Quick Answer

The way information—numbers, text, images, and sound—is encoded as binary digits (0s and 1s) inside a computer. An encoding is a rule that the writer and the reader share: in ASCII the letter 'A' is 65 (01000001), in RGB pure red is (255, 0, 0), and a sound is a list of loudness readings taken thousands of times a second. Use it to explain what a pattern of bits means, how much space something needs, and what is kept or lost when it is stored.

Why This Matters

Once you see that everything is numbers under a rule, many puzzles make sense: why a message can turn into garbled symbols (it was read with the wrong rule), why a 12-megapixel photo takes megabytes, why a heavily compressed photo looks blocky. The same 8 bits can be a letter, a number or a shade of gray. Without the rule, they mean nothing.

Intuitive Explanation

The bits 01000001 are just eight on/off switches. Read them as a number and they are 65. Read them as ASCII text and they are the letter 'A'. Read them as the brightness of a gray pixel, on a scale from 0 (black) to 255 (white), and they are a dark gray. Nothing in the bits says which; the program reading them has to know the rule. That rule is the representation.

Each kind of data has its own rule. Text: every character gets a number; ASCII uses 0 to 127, and Unicode stretches past a million so it can cover every alphabet and emoji. Color: a pixel is three numbers for red, green and blue light, each from 0 to 255, so (255, 165, 0) is orange. Sound: the wave from a microphone is measured 44,100 times a second, and each measurement is stored as a number. The rule sets the trade-offs. More measurements per second, or more bits per pixel, mean better quality and bigger files.

A representation is not the thing itself. A photo of a sunset keeps the colors of a grid of points and throws away everything between them, plus the warmth and the sound of the waves. Two files can also represent the same picture differently: a PNG keeps every pixel exactly, while a JPEG drops detail you are unlikely to notice so the file is smaller. Converting a number to base 2 is a different topic, Binary; representation is about what the numbers stand for.

Think of it like this. A representation is like a code shared by two friends: 1 means A, 2 means B, and so on. The numbers carry the message only because both use the same key; hand them to someone with a different key and the message comes out as nonsense. Computers fit this closely, except that their keys, such as ASCII and RGB, are published, not secret.

Core idea. All data in computers is ultimately numbers—representation is the mapping.


When to Use

Think about data representation when a problem asks how a letter, color, picture or sound is stored as numbers, what a pattern of bits means, or what is lost when something is saved. Questions about file size, quality settings or garbled text belong here too. If it only asks the decimal value of a binary number, that is Binary. If it only asks how many values a number of bits can hold, that is Bits and Bytes.

Tip. Ask: Does the answer depend on the agreed code that gives the bits their meaning, such as ASCII for text or RGB for color?

How to Recognize It

Check whether the question is about what bits mean, rather than how many there are or what number they make in base 2.

  1. Are you asked what a pattern of bits stands for, like which letter 01000001 is?

    Yes is data representation: you need the code, here ASCII, to read it as 'A'. If you only need its value as a number, 65, that is Binary.

  2. Could the same bits mean something different under another code?

    Yes is the sign of representation: 65 can be a letter, a gray level or part of a color. If the question is only how many values 8 bits can hold, it is Bits and Bytes.

  3. Is the goal to let anyone with the published code read the data back?

    Yes fits representation, since codes like ASCII and RGB are public. If the goal is to stop outsiders reading it, that is Encryption.

  4. Is the data kept in full, with no attempt to make it smaller?

    Yes keeps you at representation. If the question is about shrinking a file by finding repeats or dropping detail, it is Data Compression.

Data Representation vs Binary vs Bits and Bytes vs Encryption

All four deal with 0s and 1s, so they sound alike. Ask whether the question is about what the bits mean, their value as a number, how many there are, or keeping them secret.

Data Representation

Meaning
Data representation is the set of agreed codes that turn text, colors, sounds and numbers into bits and back.
Key test
You need a code table, such as ASCII or RGB, to answer.
Formula
E:D→{0,1}∗
Example
In ASCII the bits 01100001 stand for the lowercase letter 'a', which is 97.

Binary

Meaning
Binary is the base-2 number system, where each place is worth twice the place to its right.
Key test
You are converting between base 2 and base 10, with no meaning attached.
Formula
11012=8+4+0+1=13
Example
Binary 10010 equals 16 + 2 = 18 in decimal.

Bits and Bytes

Meaning
Bits and bytes are the units for counting digital data, with 8 bits in one byte.
Key test
The answer is a count of possible values or an amount of storage.
Formula
values=2bits
Example
A 3-bit code can label 23=8 different things.

Encryption

Meaning
Encryption scrambles data with a secret key so that only someone holding the key can read it.
Key test
The code is secret on purpose; representation codes are published for everyone.
Example
A messaging app turns 'meet at 5' into unreadable bytes that only your friend's phone can unlock.

Formula & Notation

E:D→{0,1}∗
Data representation defines an encoding function E:D→{0,1}∗ that maps values from a data domain D to binary strings, along with a decoding function E−1 that recovers the original data.

Worked Examples

Example 1 — Decode two bytes of ASCII

Easy

A text file stored in ASCII contains the bytes 01001000 01101001. In ASCII, 'A' is 65 and 'a' is 97, and each run of letters is in alphabetical order. What does the file say?
Show the steps and the answer
  1. Convert the first byte: 01001000 = 64 + 8 = 72.

    Each byte is first read as a binary number; the encoding then gives that number its meaning.

  2. Look up 72: 'A' is 65, so 72 is 7 letters later, 'H'.

    ASCII numbers the capital letters in order, from A = 65 to Z = 90.

  3. Convert the second byte: 01101001 = 64 + 32 + 8 + 1 = 105; 'a' is 97, so 105 is 8 letters later, 'i'.

    Lowercase letters have their own run, a = 97 to z = 122, which is why 'H' and 'h' are different numbers.

  4. Read the result: 'Hi', 2 bytes for 2 characters.

    In ASCII each character takes exactly one byte, so the file size in bytes equals the number of characters.

Answer: The file says 'Hi' (72 = H, 105 = i).

Takeaway: To read stored text, turn each byte into a number and look the number up in the encoding.

Example 2 — Same bytes, two meanings

Standard

A program reads three bytes: 01000011 01000001 01010100. What do they mean as ASCII text? What do they mean as one RGB pixel? Which reading is correct?
Show the steps and the answer
  1. Convert each byte: 01000011 = 67, 01000001 = 65, 01010100 = 84.

    The bits give numbers; they do not yet say whether the numbers are letters or colors.

  2. Read them as ASCII: 67 = C, 65 = A, 84 = T, so the text is 'CAT'.

    With A = 65, the letters C and T are 2 and 19 places later.

  3. Read them as one RGB pixel: red 67, green 65, blue 84, each out of 255.

    All three values are low and nearly equal, with blue slightly higher, so the pixel is a very dark gray with a faint blue-purple tint.

  4. Decide which reading is right: only the file type or the program's instructions can say.

    The bytes are identical in both readings, which is why opening a file in the wrong program shows nonsense.

Answer: As ASCII text the bytes spell 'CAT'; as an RGB pixel they are (67, 65, 84), a very dark bluish gray. The bits alone cannot decide; the encoding does.

Takeaway: Before interpreting bits, find out which rule they were written with.

Example 3 — Find the mistake: more bits, same size?

Application

A 3-minute mono recording takes 44,100 samples every second. Jess switches from 8 bits per sample to 16 bits per sample and writes: "The song is still 3 minutes long, so the file stays the same size; it just sounds better." Find the mistake and correct it by working out both file sizes.
Show the steps and the answer
  1. Count the samples: 3 minutes = 180 seconds, and 44,100 × 180 = 7,938,000 samples.

    The song's length decides how many samples there are, and that number is the same in both versions.

  2. At 8 bits (1 byte) per sample: 7,938,000 bytes, about 7.9 MB.

    Each sample is stored as one number, so file size = samples × bytes per sample.

  3. At 16 bits (2 bytes) per sample: 7,938,000 × 2 = 15,876,000 bytes, about 15.9 MB.

    Each sample can now take 216=65,536 loudness levels instead of 28=256, and the extra levels need extra bits.

  4. Name Jess's mistake: she counted the song's length but not the size of each stored number.

    Better quality came from more bits per sample, and those extra bits are stored 7,938,000 times.

Answer: The file doubles, from 7,938,000 bytes (about 7.9 MB) to 15,876,000 bytes (about 15.9 MB), because each sample now takes 2 bytes instead of 1.

Takeaway: Uncompressed file size = number of samples or pixels × bits for each one, so higher quality always costs space.

Where You'll See It

  • Texting an emoji that shows up as a box

    An emoji is a number (a Unicode code point) that your friend's phone couldn't map back to a picture, so it shows a box, demonstrating that text is stored as numbers under an encoding scheme.

  • Choosing a paint color by RGB sliders

    A color on screen is stored as three numbers for red, green, and blue (each 0-255), so '#FF0000' is the computer's numeric representation of pure red.

  • The same song as a CD track and an MP3

    A CD track stores 44,100 samples a second, 16 bits each, for two channels: about 10.6 MB per minute. A 128 kbps MP3 of the same song takes about 1 MB per minute, because its encoding throws away sounds people barely hear. Same song, two representations, different sizes and quality.

Common Mistakes

  1. The slip: All text is stored the same way, so encoding doesn't matter.

    Why it's tempting: Letters look identical on screen no matter how they're stored.

    Instead: ASCII, UTF-8, and UTF-16 map characters to different byte patterns. Reading bytes with the wrong encoding produces garbled text (mojibake).

  2. The slip: An image is the same thing as its file; PNG and JPEG of the same picture are identical.

    Why it's tempting: They show the same picture, so they seem to be the same data.

    Instead: The picture (the data) and its representation (PNG, JPEG, BMP) are different; each format encodes it differently with different size and quality trade-offs, and JPEG even loses some detail.

  3. The slip: Higher quality is free — more bits don't cost anything.

    Why it's tempting: On screen the higher-quality version just looks nicer, with no visible downside.

    Instead: More bits per sample or pixel means a larger file; quality and file size trade off against each other.


Mini Practice

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

  1. Write the number 13 as an 8-bit binary number.

    Hint: Find which of 8, 4, 2 and 1 add up to 13.

  2. In ASCII, 'A' is 65 and the capital letters follow in order. What is the code for 'D', and what is it in 8-bit binary?

    Hint: D is three letters after A. Then break the number into powers of 2.

  3. A pixel colour is stored as RGB (255, 0, 255) with 8 bits per channel. What colour is it, and how many bits does it use?

    Hint: Full red plus full blue, no green. Count three channels.

  4. Each of 30 students needs a different ID stored in binary. What is the fewest number of bits that gives enough IDs?

    Hint: n bits give 2n different patterns. Try n=4 and n=5.

  5. Question A: 'What is 1011 in decimal?' Question B: 'Why does a text file show strange symbols when opened with the wrong text encoding?' Which one is about data representation, not just binary conversion?

    Hint: One question changes a number's base. The other is about rules that map bits to meaning.

  6. A student says: 'The letter A and a smiley emoji both take 1 byte, because all text is stored the same way.' In UTF-8, how much space does each really take?

    Hint: UTF-8 uses a different number of bytes for different characters.

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 do emoji take more space than letters?

ASCII has only 128 codes, enough for English letters, digits and punctuation, so each fits in a single byte. Unicode now lists about 150,000 characters, including every emoji. In UTF-8, the most common way to store Unicode, plain English letters still take 1 byte, but most emoji take 4 bytes. A message full of emoji can be several times larger than the same number of plain letters.

How does a computer store negative numbers?

Most computers use a code called two's complement. In an 8-bit byte, 00000000 to 01111111 mean 0 to 127, and patterns starting with 1 stand for negatives: 11111111 means −1 and 10000000 means −128. So the byte 11111111 is 255 if read as an unsigned number and −1 if read as a signed one. The bits do not change; only the agreed reading does.

Is a number stored the same way as the digit you type?

No. The number 5 stored as a whole number is 00000101, but the character '5' typed on a keyboard is stored as its ASCII code, 53, which is 00110101. That is why a program that reads '5' from the keyboard must convert the text to a number before doing math with it. Adding the characters '5' and '5' as text joins them into '55'.

Learning Path

Data Representation

You are here

You need Binary (reading 0s and 1s as numbers) and Bits and Bytes (n bits give 2n patterns) first. Data Representation adds the rules that give those patterns meaning: character codes, RGB color, sound samples. Next, Image Representation and Audio Representation look at pictures and sound in detail, and Data Compression stores the same information in fewer bits.

See Also