Bits, bytes, GB and GiB
Video 036 of 140 in Virtualization Foundations, in the unit “Memory: RAM, addresses and virtual memory”. 3:41, with English and Hindi audio.
A disk label may say one terabyte, while the operating system shows a smaller number. Nothing has gone missing. The two sides count in different units. This matters when you run virtual machines, because memory sizes, disk sizes and network speeds all use these units, and a mix-up can make a network link look eight times faster than it really is. This article explains bits, bytes, GB and GiB, and how to convert between them on Ubuntu.
What you will learn
- A bit is one 0 or 1, and a byte is eight bits.
- A gigabyte counts powers of ten. A gibibyte counts powers of two.
- Network speeds are measured in bits, while memory and disk sizes are in bytes.
- Check the unit before you compare two numbers.
Bits and bytes, the smallest units of data
A bit is the smallest unit of data. It is a single one or zero, an on-or-off signal that every computer is built from. Eight bits make one byte. A byte holds one character of plain text, such as the letter A.
Two kinds of gigabyte: GB and GiB
Two units sound alike, but they are not the same size. A gigabyte, written GB, is one billion bytes, counted in powers of ten. A gibibyte, written GiB, is two to the power of thirty bytes. That is 1,073,741,824 bytes, which is about seven percent more than one billion.
Which unit you meet depends on the source. Disk and network makers usually count in decimal, so a size on a label may be smaller than the same size on a tool's screen.
Why network speed is written in bits
Network speeds are written in bits per second. Harbor Point's servers have 25 gigabit Ethernet ports, which means 25 billion bits every second. Divide by eight to get bytes. The link then carries about 3.1 gigabytes every second, not 25.
Note: Read a link's bits as bytes, and you overstate its speed eight times over. Always check the unit before you compare two numbers.
How to convert byte counts on Ubuntu
On Ubuntu, the numfmt command turns a number of bytes into a readable size. Its first option counts in powers of ten, which is the SI way. Its second option counts in powers of two.
numfmt --to=si 1073741824numfmt --to=iec 1073741824The free command, with the h option, shows the memory your machine has, in readable binary units.
free -hWhat goes wrong when the units are mixed
- Bits read as bytes: a network link looks eight times faster than it really is.
- Two screens that show different sizes for the same thing, because each one uses its own unit.
When you see two different sizes for one thing, check which unit each screen uses before you decide that something is wrong.
Try it yourself
You need an Ubuntu machine. You will convert the same number of bytes in two ways, then read the memory total of your machine in readable units.
Count 1073741824 bytes in powers of ten. The si option uses the SI way, with powers of ten.
numfmt --to=si 1073741824What you should see: The same bytes counted in powers of ten, as gigabytes.
Count the same bytes in powers of two, to see how a gibibyte is counted.
numfmt --to=iec 1073741824What you should see: The same bytes counted in powers of two, as gibibytes. The number is smaller than in the first result.
Show the memory total of your machine in readable binary units.
free -hWhat you should see: The memory total, in binary units, rounded for reading.
Terms
- Bit
- The smallest unit of data, a single one or zero.
- Byte
- A group of eight bits, enough to hold one character of plain text.
- Gigabyte (GB)
- One billion bytes, counted in powers of ten.
- Gibibyte (GiB)
- Two to the power of thirty bytes, which is 1,073,741,824 bytes.
Check yourself
How many bytes are in one gibibyte?
1,073,741,824 bytes, which is two to the power of thirty.
Why does a 25 gigabit link carry only about 3 gigabytes each second?
Network speeds count bits, and eight bits make one byte. So 25 billion bits divides into about 3.1 billion bytes.
Which unit is about seven percent bigger, GB or GiB?
The GiB, because it counts powers of two, and its byte count is about seven percent more than a gigabyte.
Previous: What RAM is, and how it is fitted. Next: ECC memory: catching flipped bits.