Monday, February 1, 2010

Tip #7: Understand bits and bytes

Ever wondered why, any storage media, be it a hard drive, pendrive or memory card which you own or buy, always seems to have less capacity than advertised? Suppose you buy a 8GB pendrive, when you get home and plug it in, you realise that in My Computer, it shows up as 7.44 GB or so only. Where did the remaining 0.56 GB disappear to?

Before we get to that, let's take a minute to understand how file sizes are calculated.

The scientific prefixes kilo, mega, and giga should be familiar to anyone. A kilogram is equivalent to 1,000 grams. A "megagram" (more commonly, a tonne) is equivalent to 1,000 kilograms, or 1,000,000 grams. Similarly, a "gigagram" (1,000 tonnes) is equivalent to 1,000 "megagrams", or 1,000,000 kilograms, or 1,000,000,000 grams.
To summarise this:

PrefixEquivalent to...
kilo (K)103 = 1,000
mega (M)106 = 1,000,000
giga (G)109 = 1,000,000,000
tera (T)1012 = 1,000,000,000,000

Quite unfortunately, computers weren't designed to think like us in bases of 10s (we have 10 fingers but computers don't). They were designed to think in bases of 2s (think binary 1 and 0). Since it is not possible to exactly represent 1,000 as a power of 2, the values of the prefixes in the world of computers are different:

PrefixComputer equivalent
kilo (K)210 = 1,024
mega (M)220 = 1,048,576
giga (G)230 = 1,073,741,824
tera (T)240 = 1,099,511,627,776

Back to the initial question: why is the actual capacity always less than advertised? Put simply, hardware manufacturers advertise their storage capacities using base 10 prefixes, while in actual fact, your computer will calculate the actual capacity using base 2 prefixes.

Take the 8GB pendrive for example. SanDisk/Kingston/Pendrive claims that the pendrive has 8 gigabytes of memory. In base 10,

8 × 109 = 8 × 1,000,000,000 = 8,000,000,000 bytes

The pendrive therefore has 8,000,000,000,000 bytes of memory.

Your operating system (Windows, Mac OS, Linux) calculates the storage capacity of the pendrive, by dividing the total number of bytes by 1,024:

8,000,000,000 bytes ÷ 1,024 = 7,812,500 kilobytes
7,823,500 ÷ 1,024 = 7,629.39 megabytes
7,629.39 ÷ 1,024 = 7.45 gigabytes

The actual capacity as a percentage of the advertised capacity:

7.45 GB ÷ 8 GB = 93% (approximate)

Let's take another example. When I bought my laptop, Dell advertised the hard disk capacity as 320GB.

Using Dell's math:

320GB = 320 × 1,000,000,000 = 320,000,000,000 bytes

However, real computers calculate as:

320,000,000,000 ÷ 1,024 = 312,500,000 kilobytes
312,500,000 ÷ 1,024 = 305,175.78 megabytes
305,175.78 ÷ 1,024 = 298.02 gigabytes

This can be confirmed by taking a look at the total capacity of the hard disk under Start > Control Panel > Administrative Tools > Computer Management > Disk Management:


There's a small difference of 0.07, but that's acceptable due to rounding errors in calculation.

The next time I will tell you how to understand and calculate Internet speeds (or more like, why can I only download at 100 KBps when I subscribe to 1.0 Mbps).

No comments :

Post a Comment

All comments are subject to moderation. If you don't want to sign in, comment as "Name/URL".