1 - Computer Systems (2023) Calculating File Size
|
|
Calculating filesize
Once you understand how data is used to represent different types of files, it should be possible to calculate precisely how much memory a file will require to store.
There should be no need to manually measure a file in the way that the above gentleman is attempting but rather a specific set of steps should be followed for each file type.
Calculating File size
Being able to calculate the size of a file when given specific details about it demonstrates a deep understanding of how those files are represented by data.
Calculating file size involves following a similar set of steps regardless of the file type, these steps can be broken down very generically to the following:
It is important that you realize that these calculations will only reveal the size of the raw image / sound representation. In reality the file size will be slightly larger that your calculation and this is due to the addition of Metadata. Metadata is covered in more detail on the image representation page.
For specific and detailed steps relating to each file type, please navigate through the tabs below:
Calculating file size involves following a similar set of steps regardless of the file type, these steps can be broken down very generically to the following:
- Determine how many "items" are contained within the file
- Identify how many bits are being used to represent each "item"
- Multiply - (number of bits for each item) X (the number of items)
- Divide by as appropriate to get requested unit of measurement
It is important that you realize that these calculations will only reveal the size of the raw image / sound representation. In reality the file size will be slightly larger that your calculation and this is due to the addition of Metadata. Metadata is covered in more detail on the image representation page.
For specific and detailed steps relating to each file type, please navigate through the tabs below:
Image Files - Calculating File Size
To accurately calculate the size of an image file you will need to determine the following information:
Calculating the number of pixels in an image
To determine the total number of pixels in an image you will first need to determine the image resolution. It is common for you to be given this information in this format - 3840 x 2160. The first of these numbers (3840) refers to the width of the image in pixels and the second number (2160) refers to the height of the image in pixels.
To calculate the total number of pixels in the image you simply need to multiply the numbers.
Example -
An image with the resolution 3840 X 2160 would contain 8294400 Pixels
- The total number of pixels in the image
- The bit depth of the image (How many bits are needed for each pixel)
Calculating the number of pixels in an image
To determine the total number of pixels in an image you will first need to determine the image resolution. It is common for you to be given this information in this format - 3840 x 2160. The first of these numbers (3840) refers to the width of the image in pixels and the second number (2160) refers to the height of the image in pixels.
To calculate the total number of pixels in the image you simply need to multiply the numbers.
Example -
An image with the resolution 3840 X 2160 would contain 8294400 Pixels
Determining the bit depth
Once you know exactly how many pixels an image contains, the next step is to determine the bit depth. The bit depth refers to how many bits are used to represent each pixel and this is directly affected by how many colours are used by the image.
Number of Colours |
Bits Required |
2 |
1 |
4 |
2 |
8 |
3 |
16 |
4 |
32 |
5 |
64 |
6 |
128 |
7 |
256 |
8 |
512 |
9 |
1024 |
10 |
2048 |
11 |
4096 |
12 |
8192 |
13 |
16384 |
14 |
32768 |
15 |
65536 |
16 |
The Calculation
Once you have determined the total number of pixels and the image bit depth you are ready to calculate the file size...
Lets use the duck image as an example calculation:
Lets use the duck image as an example calculation:
3840 X 2160 would contain 8294400 Image details
Total Pixels = 306
Bit depth = 2
To calculate the file size in bits we simply multiply the total pixels by the bit depth:
306 X 2 = 612 bits
The size of this image file would be 612 bits.
What about Bytes?
If you need to determine how many bytes an image file will take then you will need to divide the total amount of bits by 8 (there are 8 bits in a byte)
612 / 8 = 76.5 Bytes
What about Kibi & Mebi?
If the image file that you are dealing with is of a much higher quality then providing the file size in bytes might not be the most appropriate unit of measurement. In this case you should follow the above steps to calculate the size in bytes and then repeatedly divide by 1024 until you reached the desired unit.
Example
Lets take an imaginary image with the resolution of 3840 X 2160 and a bit depth of 16
Total Pixels = 8294400
Bit depth = 16
Total bits = 8,294,400 X 16 = 132,710,400bits
Total bytes = 132,710,400 / 8 = 16,588,800
Total Kibibytes = 16,588,800 / 1024 = 16,200 KiB
Total Mebibytes = 16,200 / 1024 = 15.82 Mib
Total Pixels = 306
Bit depth = 2
To calculate the file size in bits we simply multiply the total pixels by the bit depth:
306 X 2 = 612 bits
The size of this image file would be 612 bits.
What about Bytes?
If you need to determine how many bytes an image file will take then you will need to divide the total amount of bits by 8 (there are 8 bits in a byte)
612 / 8 = 76.5 Bytes
What about Kibi & Mebi?
If the image file that you are dealing with is of a much higher quality then providing the file size in bytes might not be the most appropriate unit of measurement. In this case you should follow the above steps to calculate the size in bytes and then repeatedly divide by 1024 until you reached the desired unit.
Example
Lets take an imaginary image with the resolution of 3840 X 2160 and a bit depth of 16
Total Pixels = 8294400
Bit depth = 16
Total bits = 8,294,400 X 16 = 132,710,400bits
Total bytes = 132,710,400 / 8 = 16,588,800
Total Kibibytes = 16,588,800 / 1024 = 16,200 KiB
Total Mebibytes = 16,200 / 1024 = 15.82 Mib
Try it yourself!
Can you determine the size of the image below in Bits, Bytes, Kibibytes and Mebibytes?
Image details
Image Resolution - 1920 X 1080
Number of colours used 16,384
Can you determine the size of the image below in Bits, Bytes, Kibibytes and Mebibytes?
Image details
Image Resolution - 1920 X 1080
Number of colours used 16,384
Bits |
Bytes |
Kibibytes |
Mebibytes |
? |
? |
? |
? |
Reveal Answer
Image details
Image Resolution - 1920 X 1080
Number of colours used 16,384
Total number of pixels = 1920 X 1080 = 2,073,600
Bit depth = 14
Total bits = 2,073,600 X 14 = 29,030,400 Bits
Total Bytes = 29,030,400 / 8 = 3,628,800
Total Kibibytes = 3,628,800 / 1024 = 3543.75
Total Mebibytes = 3543.75 / 1024 = 3.46
Image Resolution - 1920 X 1080
Number of colours used 16,384
Total number of pixels = 1920 X 1080 = 2,073,600
Bit depth = 14
Total bits = 2,073,600 X 14 = 29,030,400 Bits
Total Bytes = 29,030,400 / 8 = 3,628,800
Total Kibibytes = 3,628,800 / 1024 = 3543.75
Total Mebibytes = 3543.75 / 1024 = 3.46
Bits |
Bytes |
Kibibytes |
Mebibytes |
29030400 |
3628800? |
3543.75 |
3.46 |
Sound Files - Calculating File Size
To accurately calculate the size of an sound file you will need to determine the following information:
Determining the number of samples in a sound file
The way in which you determine the total amount of samples in a sound file will normally involve you working with the following information:
Sample rate
Length of sound file
The sample rate will normally be provided to you in an a quantity per second e.g. 10 samples per second. To calculate the the total amount of samples in a file you simply need to multiply the sample rate by the length of the sound file.
Example
If a sound file has a sample rate of 20 per second and the length is two minutes... the total number of samples could be calculated by multiplying 20 by 120 (the amount of seconds in 2 minutes.
20 X 120 = 2400 Samples
- The total number of samples in the sound file
- The sample resolution - How many pits per sample
Determining the number of samples in a sound file
The way in which you determine the total amount of samples in a sound file will normally involve you working with the following information:
Sample rate
Length of sound file
The sample rate will normally be provided to you in an a quantity per second e.g. 10 samples per second. To calculate the the total amount of samples in a file you simply need to multiply the sample rate by the length of the sound file.
Example
If a sound file has a sample rate of 20 per second and the length is two minutes... the total number of samples could be calculated by multiplying 20 by 120 (the amount of seconds in 2 minutes.
20 X 120 = 2400 Samples
Identifying the resolution (also known as bit depth)
The resolution / bit depth refers to how many bits would be required to represent each digital sound sample.
The higher the resolution (The amount of sounds that can be represented), the greater amount of bits required to represent it.
The resolution / bit depth refers to how many bits would be required to represent each digital sound sample.
The higher the resolution (The amount of sounds that can be represented), the greater amount of bits required to represent it.
Looking at the diagram above, the resolution is represented on the Y axis (Left side). This sound wave can be sampled at 16 different points (0 - 15). To represent 16 different states 4 bits would need to be used. This means that every sample in this sound file would be represented by 4 bits.
The table below details how the quantity of bits increases as sample resolution increases:
The table below details how the quantity of bits increases as sample resolution increases:
Sample Resolution |
Bits Required |
2 |
1 |
4 |
2 |
8 |
3 |
16 |
4 |
32 |
5 |
64 |
6 |
128 |
7 |
256 |
8 |
512 |
9 |
1024 |
10 |
2048 |
11 |
4096 |
12 |
8192 |
13 |
16384 |
14 |
32768 |
15 |
65536 |
16 |
The Calculation
nce you have correctly determined the sound file's total number of samples and its resolution you can calculate the total number of bits in the file by multiplying them together.
Example
Sound file details
Length of file - 1.5 minutes
Resolution - 32 Sample points
1.5 minutes = 90 seconds
32 sample points = 5 bits per sample
Total number of bits = 450 bits
As mentioned on the images tab, you will need to / by 8 and 1024 until you get the correct and requested unit of measurement.
Total number of bytes = 450 / 8 = 56.25
Example
Sound file details
Length of file - 1.5 minutes
Resolution - 32 Sample points
1.5 minutes = 90 seconds
32 sample points = 5 bits per sample
Total number of bits = 450 bits
As mentioned on the images tab, you will need to / by 8 and 1024 until you get the correct and requested unit of measurement.
Total number of bytes = 450 / 8 = 56.25
Try it yourself!
Can you determine the size of the sound files below in Bits, Bytes?
Sound File Details
Sound Resolution = 64 sample points
Sound Length = 3.5 Minutes
Can you determine the size of the sound files below in Bits, Bytes?
Sound File Details
Sound Resolution = 64 sample points
Sound Length = 3.5 Minutes
Bits |
Bytes |
? |
? |
Reveal Answer
Sound File Details
Sound Resolution = 64 sample points
Sound Length = 3.5 Minutes
Sound length = 210 seconds
64 sample points = 6 bits per sample
Total bits = 210 X 6 = 1260 Bits
Total Bytes = 1260 / 8 = 157.5
Sound Resolution = 64 sample points
Sound Length = 3.5 Minutes
Sound length = 210 seconds
64 sample points = 6 bits per sample
Total bits = 210 X 6 = 1260 Bits
Total Bytes = 1260 / 8 = 157.5
Bits |
Bytes |
1260 |
157.5 |