Main content
Course: Computers and the Internet > Unit 2
Lesson 5: Computer filesFile sizes
Computers can store much more data than they could 20 years ago, but storage is still limited. That's why file size matters: perhaps our computer's hard drive can store 10,000 GIFs of cats, but it can only store 10 full-length movies about cats.
File sizes are always measured in bytes. A byte is a sequence of 8 bits (and remember, a bit is the smallest piece of digital information, or ).
A single byte is enough bits to represent 256 numbers, because . That also means a byte is big enough to represent a single letter in the ASCII encoding standard.
A small file
If a byte is enough to represent a single letter, then a 5-letter long text file should be 5 bytes, right?
🔍 Try it yourself: Make a file with just the word "Hello" and then view the file metadata to see the total file size.
When I tried it, my computer made a file with a size of 6 bytes. I expected 5 bytes, since I typed 5 letters and the computer only needs 1 byte per letter. As it turns out, my editor added a new line automatically and that also required a single byte of representation.
byte # | character | binary |
---|---|---|
1 | H | 0100 1000 |
2 | e | 0110 0101 |
3 | l | 0110 1100 |
4 | l | 0110 1100 |
5 | o | 0110 1111 |
6 | New line | 0000 1010 |
Larger files
Files are often much larger than a few bytes. A 400x400 photo of my face is a whopping 22,096 bytes. A 33-second movie of my cat is 4,614,170 bytes.
To make it easier to talk about larger file sizes, we use larger units, starting with the kilobyte. If you're familiar with units like kilometers and kilograms, a kilobyte sounds like bytes, but it's not—or at least, it's not always.
When the term was first invented, a kilobyte referred to bytes. Computer scientists wanted to use familiar terms, but computers are based on the binary system, so it made more sense to group bytes into powers of and is . Some computers started using a kilobyte to refer to bytes—especially hard drive manufacturers, since it made their drives sound bigger. Now we live in a confusing world where kilobyte sometimes equals bytes and sometimes equals bytes.
Any given computer will be consistent in its units, so you can compare relative file sizes, even if you're not sure the exact conversion from kilobytes to bytes. In the scheme of things, 1000 is close to 1024, so you'll get a good idea for the size of the file either way.
Once a file size is bigger than kilobytes (or , depending which computer you ask), we can start using the bigger units like megabytes, gigabytes, terabytes, and petabytes.
Unit | Bytes (base 10) | Bytes (base 2) | Example | |
---|---|---|---|---|
kilobyte | KB | 10x10 icon | ||
megabyte | MB | 500 page e-book | ||
gigabyte | GB | 7 minutes of video | ||
terabyte | TB | 130,000 photos | ||
petabyte | PB | 20 million file cabinets |
The table above gives examples of how much data you can store for each unit. That column is actually a bit deceiving, because file sizes depend on whether the data is "compressed", and how much they've been compressed. 1 gigabyte could store 1 minute of uncompressed video, or it could store 1 hour of compressed low-resolution video. We'll learn much more about compression soon.
🔍 Search online for more examples of data sizes. What else could you fit in a gigabyte, terabyte, or petabyte? Share any interesting discoveries in the Tips & Thanks below.
🙋🏽🙋🏻♀️🙋🏿♂️Do you have any questions about this topic? We'd love to answer— just ask in the questions area below!
Want to join the conversation?
- I made a file with the word Hello but it in the size of the document shows 10.9 KB.(4 votes)
- When making a very small file, use a .txt
You probably made your Hello file in Microsoft Word or a Mac equivalent. These types of text applications are called "Rich Text" editors whereas Notepad is just a Text editor.
The reason why a Word document takes up more storage is that the document must save extra parts to the document like font, size, margins, headings, etc.(19 votes)
- shouldn't 8 bits be 128? because it would be 2^7 not 8, as the first bit would be 2^0(1 vote)
- As each bit can represent one of two values, then 8 bits can represent 2^8, or 256, different values(9 votes)
- What does "compressed" means?(1 vote)
- It means the file has been reduced in size. There are different ways to achieve that, lossless compression tries to find structures in the bit code and using them to reduce the amount of bits needed to represented in the data. Lossy data compression finds sections of the data that isn't really needed.(3 votes)
- What comes after petabyte?(2 votes)
- After petabyte is exabyte(1 vote)
- How do computers represent 'extra' letters such as letters with accents and double l in binary? How does the computer know that those are the letters that are being typed (I mean language-wise and the such)? Can the file size change if characters are written in another language or if the letters have accents or are extra letters? I'm just confused about the file size thing due to characters, as my (word) document gave me a different size? Why would it have done that? Thanks ahead of time for helping with the questions haha.(1 vote)
- From the author:That is a great question! I've actually written a whole article about how computers encode letters. Basically, most of them use the UTF-8 encoding to handle non-latin letters, and many of those letters require extra bytes for storage. I will send you a link to the article, as it's not yet published on the site.(2 votes)
- What does "compressed" means?(1 vote)
- What does this mean?
0100 0111 0100 1001 0100 0110
01000101 01111000 01100001 01101101 01110000 01101100 01100101(1 vote)- Assuming 4 blocks, eaching standing for a binary number it could be
4 7 4 9 4 6 4 5 7 8 6 1 6 11 7 0 6 10 6 5
in hexadecimal it would be
4 7 4 9 4 6 4 5 7 8 6 1 6 B 7 0 6 A 6 5
in Ascii it would be (in this case we need to group 8 bits together, probably the most interesting)
GIF
Example(1 vote)
- I dont quite seem to understand the conversion of hello(text) to binary(1 vote)
- how much kilobits fit in a petabyte(1 vote)
- I recently made a minecraft server and hosted it on my pc, and I can select how many gigabytes of storage in my computer I allow the server to use. So my question is, why can I get to choose the file size, and what difference it makes if the file size is big or small.(1 vote)