IB Computer Science2027 syllabus
Level view
A1.2.2

How binary is used to store data

SL & HL35 min readLesson

In one sentence: Every number, character, image, sound, and video is stored in memory and storage as bits using agreed encoding rules and metadata so software can retrieve and reconstruct the data accurately.

What you will learn

By the end of this lesson, you should be able to:

  • Explain how binary encoding schemes and file metadata enable reliable data storage and retrieval.
  • Describe how characters and strings are represented using ASCII and Unicode (including UTF-8, UTF-16, and UTF-32).
  • Explain how bitmap images, digital audio, and digital video are encoded in binary and what affects their quality and file size.
  • Distinguish binary methods for storing integers (unsigned, sign-magnitude, one's complement, two's complement, binary-coded decimal (BCD), Gray code, and Excess-N) alongside fixed-point and floating-point representations.

Before you begin

Review Principal methods of representing data (A1.2.1) so you are comfortable converting between binary, decimal, and hexadecimal, and working with bits (b) and bytes (B, 1 B = 8 b).

Key words

TermSimple meaning
Binary encodingA standardized set of rules mapping numbers, text, graphics, sound, or video into 0s and 1s.
MetadataExtra descriptive data stored alongside raw file content (such as image dimensions or sampling rate) so software can decode it correctly.
ASCIIEarly 7-bit (and 8-bit Extended) binary standard for English text characters and control codes.
UnicodeUniversal character standard assigning a unique code point to characters, scripts, symbols, and emojis worldwide.
PixelThe smallest addressable picture element in a raster (bitmap) grid, storing a colour value.
Resolution & colour depthResolution is pixel dimensions (width × height); colour depth is the number of bits assigned per pixel (2^n colours).
Sampling rate & bit depthFor audio: sampling rate is samples measured per second (Hz/kHz); bit depth is bits recording each sample's amplitude precision.
Two's complementThe standard signed binary integer system where the MSB acts as a sign bit and inverting bits + adding 1 negates a value.

The idea, step by step

Binary encoding, storage, and retrieval

Inside a computer, all stored values look alike: long streams of 0s and 1s. The single 8-bit pattern 01000100_2 has no built-in meaning by itself:

  • Interpreted as an unsigned integer, it is decimal 68.
  • Interpreted as an ASCII character, it is uppercase D.
  • Interpreted as part of a pixel or audio sample, it represents a colour intensity or sound amplitude.

To store and later retrieve data reliably without corruption or confusion, two things are needed:

  1. Standardized encoding schemes: Both the program writing the file and the program reading it must follow the same rules (e.g., UTF-8 for text, RGB bitmap layout for images, two's complement for signed integers).
  2. Metadata: Files store structural headers (such as text encoding indicators, image width, height, colour depth, or audio sampling rate and channel count) so the CPU and application know how to interpret the raw bit stream. Adding metadata slightly increases file size, while the precision chosen in an encoding trades file size and transfer speed against fidelity.

Characters and strings

Text is stored by assigning each character a numeric code and writing that integer in binary. A string is simply an ordered sequence of encoded character codes stored one after another.

ASCII and Extended ASCII

Standard ASCII (American Standard Code for Information Interchange) began as a 7-bit code representing 2^7 = 128 characters (English letters A–Z and a–z, digits 0–9, punctuation, and control characters). Extended ASCII uses all 8 bits per character (2^8 = 256 values) to add symbols and Western European characters, though different regions historically defined conflicting upper tables above 127.

For English letters in 8-bit ASCII:

  • The leftmost 3 bits indicate case: 010 for uppercase and 011 for lowercase.
  • The rightmost 5 bits match the letter's 1–26 position in the alphabet (and 00100000_2 = 32 is a space).
  • For example, D (4th letter) is 010 + 00100 = 01000100_2 (68_10), while d is 011 + 00100 = 01100100_2 (100_10).

Unicode (UTF-8, UTF-16, UTF-32)

As global networking expanded, regional 8-bit extensions proved incompatible across languages. The Unicode Standard solves this by assigning every character across world writing systems, mathematical symbols, and emojis a single universal code point while remaining backward compatible with 7-bit ASCII (0–127). Unicode characters are encoded into bytes using three common schemes:

EncodingBytes per characterKey properties and typical use
UTF-8Variable (1–4 bytes)Backward compatible with ASCII (1 byte for ASCII 0–127); dominant standard on the web and across modern OSes.
UTF-16Variable (2 or 4 bytes)Uses 2 bytes for the Basic Multilingual Plane and two 16-bit surrogate units (4 bytes) outside it; common inside Windows and Java.
UTF-32Fixed (4 bytes)Simplifies indexing because every character has equal width, but wastes storage for English/ASCII text.

In UTF-8, leading control bits tell the decoder how many bytes belong to one character so ASCII runs never waste extra space:

  • 1-byte ASCII (0xxxxxxx): 'M' (code point 77_10) is stored identically to ASCII as 01001101.
  • 2-byte character (110xxxxx 10xxxxxx): 'ü' (code point 252_10 = 11111100_2) uses 110 to signal a 2-byte sequence and 10 on the continuation byte: 11000011 10111100.
  • Similarly, 3-byte (1110xxxx ...) and 4-byte (11110xxx ...) patterns cover CJK scripts and emojis while guaranteeing that multi-byte characters never contain an all-zero byte.

Images

A bitmap (raster) image stores a picture as a 2D grid of pixels (picture elements), where each pixel holds a binary number representing its colour:

  • Resolution: The pixel dimensions (width × height). More pixels capture finer edges and detail; too few pixels on a large screen causes visible blockiness (pixelation). Screen clarity also depends on pixel density (PPI, pixels per inch).
  • Colour depth (bit depth): The number of bits per pixel (n), allowing 2^n distinct colours:
    • 1-bit: 2^1 = 2 colours (monochrome).
    • 8-bit: 2^8 = 256 colours (simple web graphics).
    • 24-bit (True Colour): 2^24 ≈ 16.8 million colours, built from three 8-bit channels (Red, Green, Blue, each 0–255 or 00–FF in hex). For instance, #2A7F62 stores R = 42, G = 127, B = 98. Low colour depth can cause banding, where smooth shading splits into visible stripes.

The raw pixel storage requirement (before adding metadata headers) is:

Raw pixel data (bits) = width × height × colour depth

For example, a 400 × 300 graphic supporting 16 colours (4-bit depth, since 2^4 = 16) needs 400 × 300 × 4 = 480,000 bits = 60,000 bytes = 60 KB (decimal) for pixel data alone, plus metadata (dimensions, colour depth, format headers) required so software can reconstruct the image accurately.

Audio

Real-world sound is a continuous analogue wave of air-pressure variations (amplitude). An analogue-to-digital converter (ADC) turns it into binary numbers through sampling:

  1. Sampling rate: How many amplitude measurements are recorded per second, measured in Hertz (Hz or kHz; e.g., 44.1 kHz for CD audio, 48 kHz for studio/video audio). Higher sampling rates capture rapid frequency changes more faithfully.
  2. Bit depth: How many bits store each sample (16-bit yields 65,536 amplitude levels; 24-bit yields 16,777,216 levels). Greater bit depth reduces quantization distortion.
  3. Channels: Mono uses 1 channel; stereo uses 2 channels (left and right).

The raw uncompressed audio size is:

Audio size (bits) = sampling rate (Hz) × bit depth (bits) × channels × duration (s)

For instance, a 20-second 24 kHz, 8-bit mono voice clip requires 24,000 × 8 × 1 × 20 = 3,840,000 bits = 480,000 bytes = 480 KB. Audio files are saved either uncompressed (WAV, AIFF), losslessly compressed (FLAC, exact recovery), or lossily compressed (MP3, discarding frequencies less audible to human hearing).

Video

Digital video bundles frames (sequences of still bitmap images), audio tracks, metadata, and optional subtitles or captions inside a container format such as MP4, MKV, or AVI. Playing 24–60 frames per second (fps) creates the illusion of smooth motion.

Because raw uncompressed frames would be enormous, video encoders reduce data in two main ways alongside switching from RGB to YUV colour representation (which separates brightness/luminance, where human vision is sharpest, from colour detail):

  • Spatial (intraframe) compression: Eliminates redundant pixel or colour detail within each individual frame, much like still-image compression.
  • Temporal (interframe) compression: Eliminates redundancy between consecutive frames in a sequence, storing predicted differences and motion rather than repeating unchanged background pixels in every frame.

Binary methods for storing integers (and fractional numbers)

Different binary integer formats serve different computing needs across an 8-bit system:

Method8-bit rangeRepresentations of 0How -12 (from +12 = 00001100) is encodedKey use / trade-off
Unsigned binary0 to +2551 (00000000)N/A (positive only)Simple counts, memory addresses, pixel channels.
Sign-magnitude-127 to +1272 (00000000, 10000000)10001100 (MSB 1 = minus, magnitude unchanged)Intuitive sign bit, but two zeros complicate hardware arithmetic.
One's complement-127 to +1272 (00000000, 11111111)11110011 (invert all bits)Two zeros remain; end-around carry needed in addition.
Two's complement-128 to +1271 (00000000)11110100 (invert all bits, then add 1)Standard for CPU integer arithmetic; single zero and unified addition/subtraction circuits.

Three specialized integer encodings are also used in hardware and low-level systems:

  • Binary-coded decimal (BCD): Stores each decimal digit (0–9) separately in its own 4-bit nibble. Example: decimal 73 becomes 0111 0011. Avoids binary rounding errors in financial and clock displays, at the cost of lower storage density and extra carry logic.

  • Gray code (reflected binary code): Orders values so two successive numbers differ by only 1 bit. This prevents multi-bit transition glitches in mechanical rotary encoders and sensors.

    Decimal01234567
    Standard binary000001010011100101110111
    Gray code000001011010110111101100
  • Excess-N (biased representation): Adds a fixed bias N to every integer before storing it as an unsigned pattern (and subtracts N on decode). In Excess-127 (+127), -127 encodes as 00000000_2 (0) and +127 encodes as 11111110_2 (254), making signed values easy to compare and sort as unsigned bit patterns.

For fractional (real) numbers, systems use either:

  • Fixed-point: Allocates a fixed split of integer and fractional bits (e.g., 4.4-bit +6.75 = 0110.1100, using binary place fractions 1/2, 1/4, 1/8, 1/16). Simple and fast, but severely limited in range and precision.
  • Floating-point (IEEE 754 single-precision, 32-bit): Stores 1 sign bit (0 = positive, 1 = negative), 8 biased exponent bits (Excess-127), and 23 normalized mantissa bits (omitting the leading 1). For example, +6.75_10 = 110.11_2 = 1.1011 × 2^2 encodes as sign 0, exponent 2 + 127 = 129 = 10000001, and mantissa 10110000000000000000000. It handles huge and tiny values, though rounding errors can still occur.

Worked example

A weather display board receives an alert packet containing a signed 8-bit temperature, a 2-character ASCII code "OK", a 20 × 10 1-bit monochrome icon, and a 2-second 8 kHz 8-bit mono chime:

  1. Signed temperature (-6 °C in 8-bit two's complement):
    • +6_10 = 00000110_2.
    • Invert bits: 11111001_2.
    • Add 1: 11111010_2 (-128 + 64 + 32 + 16 + 8 + 2 = -6).
  2. String "OK" in 8-bit ASCII:
    • 'O' is the 15th letter (010 + 01111 = 01001111_2).
    • 'K' is the 11th letter (010 + 01011 = 01001011_2).
  3. Raw bitmap icon (20 × 10 at 1-bit depth):
    • 20 × 10 × 1 = 200 bits = 25 bytes (plus metadata header storing width = 20, height = 10, and depth = 1).
  4. Raw audio chime (8,000 Hz, 8-bit, 1 channel, 2 s):
    • 8,000 × 8 × 1 × 2 = 128,000 bits = 16,000 bytes = 16 KB.

Each component uses an agreed binary scheme so the board's software decodes every field accurately.

Check your understanding

  1. Why can the exact same 8 bits (01000100_2) represent either an integer or a letter, and what prevents software from mixing them up when opening a file?
  2. Compare UTF-8 and UTF-32 in terms of storage size for mostly English text and processing complexity.
  3. Calculate the raw pixel-data size in kilobytes (KB, 1 KB = 1,000 bytes) for an uncompressed 300 × 200 image with a 16-bit colour depth, and explain why the saved file on disk is larger than this number.
  4. Contrast sign-magnitude, one's complement, and two's complement for representing signed 8-bit integers.

Common mix-up

It is easy to think: Binary files only store numbers, or signed 8-bit two's complement covers -127 to +127 just like sign-magnitude.

Instead, remember: All data (characters, pixels, audio samples, video frames, and numbers) is encoded into binary, and metadata and standards tell software how to interpret those bits. Because two's complement uses only one pattern for zero (00000000), the remaining pattern (10000000) gives it an asymmetric 8-bit range of -128 to +127.

Quick recap

  • Storage and retrieval: Standardized encoding rules plus metadata let computers turn binary streams back into meaningful integers, text, images, audio, and video.
  • Text: ASCII (7/8 bits) encodes basic Latin text; Unicode covers global scripts via UTF-8 (1–4 bytes, ASCII-compatible), UTF-16 (2/4 bytes), and UTF-32 (4 bytes).
  • Images and audio: Bitmap size scales with width × height × colour depth; audio ADC size scales with sampling rate × bit depth × channels × duration.
  • Video: Containers combine frames, audio, metadata, and subtitles; YUV colour conversion, spatial (intraframe) compression, and temporal (interframe) compression shrink video files.
  • Numbers: Two's complement (-128 to +127, one zero) is standard for signed integers; BCD, Gray code, and Excess-N solve specialized encoding needs, while fixed-point and IEEE 754 floating-point store fractional values.

Textbook reading

  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1 Computer fundamentals > A1.2 Data representation and computer logic > A1.2.2 How binary is used to store data, Book pp. 31–51 (PDF pp. 41–61).
  • Read these pages to reinforce the lesson; this original explanation does not replace the textbook.

Sources and further learning

  • IB Computer Science Guide (first assessment 2027), A1.2.2: Explain how binary is used to store data (Guide p. 29; PDF p. 35).
  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1.2.2 How binary is used to store data, Book pp. 31–51 (PDF pp. 41–61). All worked examples and tables above are original.
Check your understanding5 questions · 10 marks · 12 min
Take the lesson check
Something not right?