Skip to content
Educora
IntermediateGrades 9–1022 min13 / 59

Encoding sound and video

How sound becomes a digital code: sampling rate, bit depth, mono and stereo, the size of a sound file V = f · i · t · k; video as a sequence of frames; lossy and lossless compression, sound and video formats — with solved problems.

Check yourself
In this lesson you will learn
  • Explain how analog sound is sampled and quantized
  • Find the size, duration, sampling rate or bit depth of a sound file with V = f · i · t · k
  • Calculate the size of uncompressed video and explain why lossy compression is needed

A 4-minute song takes about 40 MB as a CD-quality WAV file but only about 3.7 MB as a 128 kbit/s MP3, and the ear hardly notices the difference. A one-minute video from a phone can take tens or even hundreds of megabytes. How do sound and video become numbers, and what decides how many numbers there are? In this lesson we will learn to calculate the size of sound and video files.

Encoding sound and video is part of the entrance exam syllabus. The four entrance exams of 2025–2026 had no separate task on it, but the calculation is familiar: as in the lesson “Computer graphics: encoding raster and vector images”, every measurement is written with i bits, and size = number of measurements · i. And a video is simply a sequence of those raster images.

From analog to digital sound

Sound is a vibration of the air — a wave. A microphone turns the vibration into an electrical signal that changes continuously over time: an analog signal. A computer can store only numbers, so the signal is measured at equal intervals and the value of each measurement is written down as a number.

Definition
Sampling rate

How many times per second the signal is measured (f). It is given in hertz (Hz): 44.1 kHz means 44,100 measurements per second. Measuring the signal at separate moments is called sampling.

Definition
Bit depth

The number of bits used to write the value of one measurement (i). The measured value is rounded to the nearest of 2ⁱ levels — this is called quantization: 8 bits give 256 levels, 16 bits give 65,536.

01234567tanalog signaldigital values: 3 bits, 8 levels
Sampling (points in time) and quantization (rounding to levels). The higher the rate and the depth, the closer the steps follow the signal.

Sound can be recorded with one or more channels: mono — one channel, stereo — two (left and right), a 5.1 home-cinema system — 6 channels. Each channel is recorded separately, so a stereo file is twice as big as the same recording in mono.

Qualityfik1 second of sound
Telephone8 kHz8 bits1 (mono)64,000 bits = 8000 bytes
Audio CD44.1 kHz16 bits2 (stereo)1,411,200 bits = 176,400 bytes
Studio recording (one option)96 kHz24 bits2 (stereo)4,608,000 bits = 576,000 bytes
The last column is f · i · k — how many bits are recorded per second.

The size of a sound file: V = f · i · t · k

V = f · i · t · k
where:
  • Vthe size of the sound file (bits)
  • fthe sampling rate (Hz)
  • ithe bit depth (bits)
  • tthe duration of the recording (s)
  • kthe number of channels: mono 1, stereo 2

In fact it is “number of measurements × bits per measurement”: f · t · k measurements of i bits each.

  1. 1
    Convert kHz into Hz

    44.1 kHz = 44,100 Hz, 22.05 kHz = 22,050 Hz: in frequencies “kilo” means 1000, not 1024.

  2. 2
    Convert the time into seconds

    2 min = 120 s, 1 h = 3600 s.

  3. 3
    Multiply

    V = f · i · t · k bits. Do not forget to multiply by 2 for stereo.

  4. 4
    Convert the unit

    bits ÷ 8 = bytes; bytes ÷ 1024 = KB; KB ÷ 1024 = MB.

The size of a sound file

1) How many bytes does 1 minute of CD-quality sound (44.1 kHz, 16 bits, stereo) take?
2) What is the size in KB of a 10-second recording in telephone quality (8 kHz, 8 bits, mono)?
3) Stereo sound is recorded for 64 seconds at 32 kHz with a bit depth of 16. What is the file size in KB?
A) 4000 B) 8000 C) 1000 D) 16,000 E) 8192

Show solution
1) V = 44,100 · 16 · 60 · 2 = 84,672,000 bits = 84,672,000 ÷ 8 = 10,584,000 bytes ≈ 10.1 MB.
2) V = 8000 · 8 · 10 · 1 = 640,000 bits = 80,000 bytes = 80,000 ÷ 1024 ≈ 78.1 KB.
3) V = 32,000 · 16 · 64 · 2 = 65,536,000 bits = 8,192,000 bytes = 8,192,000 ÷ 1024 = 8000 KB (B). E (8192) is the mistake of multiplying kHz by 1024.
Working backwards

1) Mono sound is recorded at 48 kHz with a bit depth of 16, and the file takes 1875 KB. How many seconds long is the recording?
2) A stereo, 8-bit, 10-second sound file takes 312.5 KB. What is the sampling rate in Hz?
3) A 5-second mono recording made at 8 kHz takes 60,000 bytes. What is the bit depth? How many levels are there?

Show solution
1) t = V ÷ (f · i · k) = 1875 · 8192 ÷ (48,000 · 16 · 1) = 15,360,000 ÷ 768,000 = 20 s.
2) f = V ÷ (i · t · k) = 312.5 · 8192 ÷ (8 · 10 · 2) = 2,560,000 ÷ 160 = 16,000 Hz = 16 kHz.
3) i = 60,000 · 8 ÷ (8000 · 5 · 1) = 480,000 ÷ 40,000 = 12 bits; levels: 2¹² = 4096.
Ratios: the quality changes

1) Sound was recorded at 44.1 kHz, 16 bits, stereo. It was then re-recorded at 22.05 kHz, 8 bits, mono (same duration). How many times smaller is the file?
A) 2 B) 4 C) 8 D) 16 E) 6
2) The sampling rate is doubled and stereo is changed to mono. How does the size change?
3) The number of levels goes from 256 to 65,536. How many times larger does the file become?

Show solution
1) Every factor halves: f (44,100 → 22,050), i (16 → 8), k (2 → 1). V₁ / V₂ = 2 · 2 · 2 = 8 (C).
2) f · k = (2f) · (k / 2): the product stays the same ⇒ the size does not change.
3) 256 = 2⁸ ⇒ 8 bits, 65,536 = 2¹⁶ ⇒ 16 bits; the file grows 2 times (not 256 times!).
Sending sound over a channel

1) Stereo sound is recorded for 30 seconds at 16 kHz with a bit depth of 16. How many seconds does it take to send it over a 256,000 bit/s channel?
2) What is the lowest channel rate that carries a phone call (8 kHz, 8 bits, mono) without delay? (The formula I = v · t is in the lesson “Measuring information: bits, bytes and units”.)

Show solution
1) V = 16,000 · 16 · 30 · 2 = 15,360,000 bits; t = 15,360,000 ÷ 256,000 = 60 s. So sending the recording takes twice as long as the recording itself.
2) One second of speech: 8000 · 8 · 1 = 64,000 bits ⇒ the channel must carry at least 64,000 bit/s.
Python
f, i, t, k = 44100, 16, 60, 2          # Hz, bits, seconds, channels
bits = f * i * t * k
print(bits, "bits")
print(bits // 8, "bytes")
print(round(bits / 8 / 2**20, 2), "MB")
▸ Expected output
84672000 bits
10584000 bytes
10.09 MB
The size of 1 minute of CD-quality sound. Change f, i, t and k to check the problems above.

Video: a sequence of frames

A video consists of raster images — frames — that replace each other quickly, and the eye sees them as motion. Cinema uses 24 frames per second, television 25 or 30, and games and sports broadcasts often 60. A video usually has a sound track too.

Definition
Frame rate

The number of frames shown per second (n), measured in frames per second (fps).

V = W · H · i · n · t
where:
  • W · H · ithe size of one frame (bits), as for a raster image
  • nthe frame rate (frames per second)
  • tthe duration of the video (s)

If there is a sound track, add its size f · i · t · k too. The formula gives the size of uncompressed video.

The size of a video

1) How many MB is an 8-second silent animation, 256 × 128, 256 colors, 16 frames per second?
2) How many bytes does a 10-second 640 × 480 True Color video at 25 fps take without compression?
3) About how many GB is a 1-minute Full HD (1920 × 1080) True Color video at 30 fps without compression?

Show solution
1) One frame: 2⁸ · 2⁷ · 8 bits = 2¹⁸ bits = 32 KB. Number of frames: 16 · 8 = 128.
V = 128 · 32 = 4096 KB = 4 MB.
2) One frame: 640 · 480 · 3 = 921,600 bytes; V = 921,600 · 25 · 10 = 230,400,000 bytes ≈ 219.7 MB.
3) V = 1920 · 1080 · 3 · 30 · 60 = 11,197,440,000 bytes ≈ 10.4 GB — for just one minute! That is why video is never stored uncompressed.

Compression and formats

Uncompressed sound and video take a lot of space, so they are compressed. There are two ways: lossless compression restores the original data exactly when the file is opened (ZIP archives, PNG, FLAC); lossy compression throws away details the ear and eye hardly notice and makes the file much smaller (MP3, AAC, JPEG, and video compressed with the H.264 and H.265 codecs).

k = V₀ / Vk = V₀ / V
where:
  • kthe compression ratio — how many times smaller the file became
  • V₀the size before compression
  • Vthe size of the compressed file

For streamed sound and video you can compare the rates in bit/s instead of the sizes.

The compression ratio

1) CD sound takes 1,411,200 bits per second, while an MP3 takes 128 kbit/s (128,000 bit/s). What is the compression ratio, roughly?
2) How many MB does a 4-minute song take as a CD-quality WAV and as a 128 kbit/s MP3?
3) One minute of uncompressed Full HD video is 11,197,440,000 bytes. If the video is streamed at 5 Mbit/s (5,000,000 bit/s), what is the compression ratio, roughly?

Show solution
1) k = 1,411,200 ÷ 128,000 ≈ 11 times.
2) 4 min = 240 s. WAV: 176,400 · 240 = 42,336,000 bytes ≈ 40.4 MB; MP3: 128,000 · 240 ÷ 8 = 3,840,000 bytes ≈ 3.7 MB.
3) The stream in 1 minute: 5,000,000 · 60 ÷ 8 = 37,500,000 bytes. k = 11,197,440,000 ÷ 37,500,000 ≈ 300 times.
KindFormatsCompression
SoundWAVusually uncompressed
SoundFLAClossless
SoundMP3, AAC, OGGlossy
VideoMP4, MKV, AVI, MOV, WebMcontainers; the video inside is usually compressed with a lossy codec (H.264, H.265)

This completes the module: text, pictures, sound and video all follow the same idea — number of measurements (symbols, pixels) × bits per measurement. Once you know this rule, any encoding problem takes just a few lines.

Key points

  • Sound is sampled (measured f times per second), and each measurement is written with i bits (2ⁱ levels).
  • The size of a sound file is V = f · i · t · k; mono k = 1, stereo k = 2.
  • For frequencies 1 kHz = 1000 Hz; divide by 8 to go from bits to bytes and by 1024 to go from bytes to KB.
  • A video is made of frames: V = W · H · i · n · t (plus the sound track).
  • Lossless compression restores the data exactly (FLAC, PNG, ZIP); lossy compression throws details away (MP3, JPEG, H.264).
  • Compression ratio k = V₀ / V: from CD sound to a 128 kbit/s MP3 it is about 11.

Check yourself

12 questions. Every correct answer earns XP.

1 / 12
What does the sampling rate show?