Previous Section  < Day Day Up >  Next Section

Recipe 5.6. Calculating Hard Drive Capacity

5.6.1 Problem

You want to measure precisely the capacity of a hard drive, but you can't seem to get a straight answer because of confusion over measurement values. How much is a megabyte—is it 1 million bytes, or 220 bytes? Which measurement is used for the rated size of your drive?

5.6.2 Solution

Use fdisk to get the total disk size in bytes:

# /sbin/fdisk -l /dev/hda

Disk /dev/hda: 20.5 GB, 20576747520 bytes

Then do a little math to get the value in gibibytes, which is a power of 2:

20576747520 / 1,073,741,824 = 19.16 gibibytes

Gigabytes, which are most often used as powers of 10, are easy to figure:

20576747520 / 10 = 20.58 gigabytes

Table 5-1 shows a comparison of binary and decimal multiples.

Table 5-1. Comparison of binary and decimal multiples

Base-2 values


Base-10 values



1,024 bytes



1,000 bytes



1,048,576 bytes



1,000,000 bytes



1,073,741,824 bytes



1,000,000,000 bytes


5.6.3 Discussion

In 1998, the International Electrotechnical Commission (IEC) decided that we needed new terminology and ratified some nice new words for us to use. So now we have kibibyte, mibibyte, gibibyte, tebibyte, and so forth. Even though they are weird to pronounce, it's good to have precise terminology.

There are times when it is important to know the precise size of a drive, such as when you're selecting drives for a RAID array, or calculating the number of disks needed for a system backup. The debate over how much a gigabyte or megabyte is will probably continue for as long as computer users have breath, and drive manufacturers use whatever math gives the most inflated numbers. In the example above, it appears that using gigabytes inflates the drive capacity by well over one gigabyte (or gibibyte—take your pick). As the base unit of measurement is a byte, I say stick with base 2.

To get an unambiguous, absolute value, you're probably stuck with bytes—unless someone starts messing with them, too.

5.6.4 See Also

    Previous Section  < Day Day Up >  Next Section