Key Formulas
Text File Size
Characters × Bits per character
Image File Size
Width × Height × Colour depth
Sound File Size
Sample rate × Bit depth × Duration × Channels
Unit Conversion
8 bits = 1 byte
1000 bytes = 1 KB
1000 KB = 1 MB
Text File Size in ASCII
Problem
A text file contains the sentence: "Hello World!" (12 characters including space and punctuation)
The file uses ASCII encoding (8 bits per character).
Calculate the file size in bits and bytes.
Solution
Identify the values
- Number of characters = 12
- Bits per character (ASCII) = 8 bits
Apply the formula
File size (bits) = Characters × Bits per character
File size (bits) = 12 × 8 = 96 bits
Convert to bytes
File size (bytes) = 96 ÷ 8 = 12 bytes
Answer
The file size is 96 bits or 12 bytes.
Notice: In ASCII, 1 character = 1 byte, so characters = bytes!
Comparing ASCII and Unicode File Sizes
Problem
A document contains 500 characters of text.
Calculate the file size difference between ASCII (8-bit) and Unicode (16-bit) encoding.
Solution
Calculate ASCII file size
File size = 500 × 8 = 4,000 bits
In bytes: 4,000 ÷ 8 = 500 bytes
Calculate Unicode file size
File size = 500 × 16 = 8,000 bits
In bytes: 8,000 ÷ 8 = 1,000 bytes
Calculate the difference
Difference = 1,000 - 500 = 500 bytes
Or: 1,000 ÷ 500 = 2× larger
Answer
Unicode file is 500 bytes larger (double the size of ASCII).
Unicode uses 2× more bits per character, so files are 2× larger.
Finding ASCII Character Codes
Problem
In ASCII, the character 'A' has the code 65 and 'a' has the code 97.
What are the ASCII codes for 'G' and 'g'?
Solution
Find position of 'G' in alphabet
G is the 7th letter of the alphabet
Calculate uppercase 'G' code
A = 65, and G is 6 positions after A
G = 65 + 6 = 71
Calculate lowercase 'g' code
a = 97, and g is 6 positions after a
g = 97 + 6 = 103
Answer
'G' = 71, 'g' = 103
Pattern: Lowercase letters are always 32 more than uppercase (103 - 71 = 32)
Image File Size Calculation
Problem
A digital photograph has the following properties:
- Resolution: 1920 × 1080 pixels (Full HD)
- Colour depth: 24 bits (true colour)
Calculate the uncompressed file size in megabytes (MB).
Solution
Calculate total pixels
Total pixels = Width × Height
Total pixels = 1920 × 1080 = 2,073,600 pixels
Calculate file size in bits
File size = Total pixels × Colour depth
File size = 2,073,600 × 24 = 49,766,400 bits
Convert to bytes
File size = 49,766,400 ÷ 8 = 6,220,800 bytes
Convert to megabytes
File size = 6,220,800 ÷ 1,000,000 = 6.22 MB
Answer
The uncompressed file size is approximately 6.22 MB.
Real JPEG files are much smaller due to compression!
Effect of Colour Depth on File Size
Problem
An image is 800 × 600 pixels.
Calculate the file size with: (a) 8-bit colour depth, (b) 24-bit colour depth.
How many colours can each version display?
Solution
Calculate total pixels
Total pixels = 800 × 600 = 480,000 pixels
Calculate 8-bit version
File size = 480,000 × 8 = 3,840,000 bits
In bytes = 3,840,000 ÷ 8 = 480,000 bytes (480 KB)
Colours = 28 = 256 colours
Calculate 24-bit version
File size = 480,000 × 24 = 11,520,000 bits
In bytes = 11,520,000 ÷ 8 = 1,440,000 bytes (1.44 MB)
Colours = 224 = 16,777,216 colours
Answer
| 8-bit | 24-bit | |
|---|---|---|
| File size | 480 KB | 1.44 MB |
| Colours | 256 | 16.7 million |
24-bit is 3× larger but has 65,536× more colours!
Sound File Size (Mono)
Problem
A mono audio recording has the following properties:
- Sample rate: 44,100 Hz (CD quality)
- Bit depth: 16 bits
- Duration: 30 seconds
Calculate the file size in MB.
Solution
Identify the values
- Sample rate = 44,100 samples per second
- Bit depth = 16 bits per sample
- Duration = 30 seconds
- Channels = 1 (mono)
Apply the formula
File size (bits) = Sample rate × Bit depth × Duration
File size (bits) = 44,100 × 16 × 30
File size (bits) = 21,168,000 bits
Convert to bytes
File size = 21,168,000 ÷ 8 = 2,646,000 bytes
Convert to megabytes
File size = 2,646,000 ÷ 1,000,000 = 2.65 MB
Answer
The mono audio file is approximately 2.65 MB.
Stereo Sound File Size
Problem
A stereo music track has the following properties:
- Sample rate: 44,100 Hz
- Bit depth: 16 bits
- Duration: 3 minutes
- Channels: 2 (stereo)
Calculate the uncompressed file size in MB.
Solution
Convert duration to seconds
Duration = 3 minutes × 60 = 180 seconds
Apply the formula (including channels)
File size (bits) = Sample rate × Bit depth × Duration × Channels
File size (bits) = 44,100 × 16 × 180 × 2
File size (bits) = 254,016,000 bits
Convert to bytes then MB
Bytes = 254,016,000 ÷ 8 = 31,752,000 bytes
MB = 31,752,000 ÷ 1,000,000 = 31.75 MB
Answer
The stereo audio file is approximately 31.75 MB.
This is why MP3s use compression - a 3-minute MP3 is typically only 3-5 MB!
Comparing Audio Quality Settings
Problem
Calculate the file size for a 60-second mono recording at:
- Telephone quality: 8,000 Hz, 8-bit
- CD quality: 44,100 Hz, 16-bit
How much larger is the CD quality file?
Solution
Calculate telephone quality
Bits = 8,000 × 8 × 60 = 3,840,000 bits
Bytes = 3,840,000 ÷ 8 = 480,000 bytes (480 KB)
Calculate CD quality
Bits = 44,100 × 16 × 60 = 42,336,000 bits
Bytes = 42,336,000 ÷ 8 = 5,292,000 bytes (5.29 MB)
Compare the sizes
Ratio = 5,292,000 ÷ 480,000 = 11× larger
Answer
| Telephone | CD Quality | |
|---|---|---|
| File size | 480 KB | 5.29 MB |
CD quality is approximately 11× larger than telephone quality.
Higher sample rate (5.5×) combined with higher bit depth (2×) = 11× more data!
Practice Problems
Try these on your own, then reveal the answers to check.
Practice 1: Text File
A text file contains 2,500 characters using Unicode (16-bit). What is the file size in KB?
2,500 × 16 = 40,000 bits
40,000 ÷ 8 = 5,000 bytes
5,000 ÷ 1,000 = 5 KB
Practice 2: Image File
A 4K image (3840 × 2160) uses 24-bit colour. What is the file size in MB?
Pixels = 3,840 × 2,160 = 8,294,400
Bits = 8,294,400 × 24 = 199,065,600
Bytes = 199,065,600 ÷ 8 = 24,883,200
MB = 24,883,200 ÷ 1,000,000 = 24.88 MB
Practice 3: Sound File
A 2-minute stereo recording at 48,000 Hz with 24-bit depth. What is the file size in MB?
Duration = 120 seconds
Bits = 48,000 × 24 × 120 × 2 = 276,480,000
Bytes = 276,480,000 ÷ 8 = 34,560,000
MB = 34,560,000 ÷ 1,000,000 = 34.56 MB
Practice 4: ASCII Codes
If 'Z' has ASCII code 90, what are the codes for 'X' and 'z'?
X is 2 positions before Z: 90 - 2 = 88
Lowercase letters are 32 more than uppercase
z = 90 + 32 = 122