Vibrantly colored binary numbers! Matejmo / Getty ImagesIf you've spent even a few minutes using a computer, you've likely encountered the terms bits and bytes. Both RAM and hard disk storage capacities are measured in bytes, and so are the sizes of files you see in a file viewer.
You might come across an ad saying, "This computer has a 32-bit Pentium processor with 64 megabytes of RAM and 2.1 gigabytes of hard disk space." Additionally, many Mytour articles reference bytes (like in How CDs Work). In this article, we'll dive into bits and bytes to give you a thorough understanding.
Understanding Decimal Numbers
The simplest way to grasp the concept of bits is by comparing them to something familiar: digits. A digit represents a single position that can hold any value from 0 to 9. Digits are typically combined in groups to form larger numbers. For instance, in the number 6,357, there are four digits. In this number, the 7 occupies the "ones place," the 5 occupies the tens place, the 3 occupies the hundreds place, and the 6 occupies the thousands place. If you'd like to be more detailed, you can express it like this:
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1) = 6000 + 300 + 50 + 7 = 6357
Another approach to express this would be by using powers of 10. If we represent the concept of "raised to the power of" using the "^" symbol (so, for example, "10 squared" is written as "10^2"), you could express the number this way:
(6 * 10^3) + (3 * 10^2) + (5 * 10^1) + (7 * 10^0) = 6000 + 300 + 50 + 7 = 6357
This expression shows that each digit acts as a placeholder representing the next higher power of 10, starting from the first digit with 10 raised to the power of zero.
This should be familiar — we use decimal digits every day. What's interesting about number systems is that there's no rule requiring us to have 10 distinct values for a digit. Our base-10 system likely developed because we have 10 fingers, but if we had evolved with eight fingers, we would probably use a base-8 system. Number systems can be based on any value, and there are numerous situations where using different bases is advantageous.
Computers rely on the base-2 number system, also called the binary number system (just like base-10 is known as the decimal system). Learn more about how this works in the next section.
The Base-2 System and the 8-bit Byte
The reason computers use the base-2 system is that it simplifies their construction with current electronic technology. While it's possible to create base-10 computers, they would be prohibitively expensive today. On the other hand, base-2 systems are much more affordable.
Computers utilize binary numbers, meaning they use binary digits instead of decimal digits. The term bit comes from the abbreviation for "Binary digIT." While decimal digits can represent 10 values (from 0 to 9), bits are restricted to just two values: 0 and 1. As a result, a binary number consists solely of 0s and 1s, like this: 1011. So, how do you determine the value of the binary number 1011? You calculate it the same way we did with 6357, but using a base of 2 rather than base 10. Here's how:
(1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0) = 8 + 0 + 2 + 1 = 11
In binary numbers, each bit represents an increasing power of 2. This makes counting in binary relatively simple. If you count from 0 to 20, the numbers in both decimal and binary would appear like this:
0 = 0 1 = 1 2 = 10 3 = 11 4 = 100 5 = 101 6 = 110 7 = 111 8 = 1000 9 = 1001 10 = 1010 11 = 1011 12 = 1100 13 = 1101 14 = 1110 15 = 1111 16 = 10000 17 = 10001 18 = 10010 19 = 10011 20 = 10100
Looking at this sequence, you can see that 0 and 1 are the same in both decimal and binary number systems. When you reach the number 2, you notice the first occurrence of carrying in the binary system. If a bit is 1 and you add 1 to it, the bit turns to 0, and the next bit becomes 1. This rollover effect can be seen when transitioning from 15 to 16, where 1111 becomes 10000.
In computers, bits are rarely seen by themselves. They are almost always grouped together into sets of 8 bits, which are referred to as bytes. But why are there 8 bits in a byte? It's like asking, 'Why are there 12 eggs in a dozen?' The 8-bit byte was the result of experimentation and decision-making over the last 50 years.
With 8 bits making up a byte, you can represent 256 distinct values, ranging from 0 to 255. Here's how those values appear:
0 = 00000000 1 = 00000001 2 = 00000010 ... 254 = 11111110 255 = 11111111
In the article How CDs Work, you'll find that a CD uses 2 bytes, or 16 bits, for each sample. This allows each sample to cover a range from 0 to 65,535, like this:
0 = 0000000000000000
1 = 0000000000000001
2 = 0000000000000010
...
65534 = 1111111111111110
65535 = 1111111111111111Now, let's explore one common way in which bytes are utilized.
The Standard ASCII Character Set
Bytes are often used to represent individual characters in a text file. In the ASCII character set, each number from 0 to 127 corresponds to a specific character. Many computers extend the ASCII set to include the full byte capacity, allowing for 256 possible characters. The upper half of these characters is typically used for special symbols, such as accented letters from various languages.
Below, you'll find the 127 standard ASCII codes. Computers use these codes to store text files, whether on disk or in memory. For instance, if you create a text file in Windows 95/98 using Notepad with the sentence, "Four score and seven years ago," each character (including spaces, which are represented by ASCII character 32) takes up one byte of memory. The same holds true when the file is saved to disk.
Try this simple test: Open a new file in Notepad and type the sentence, "Four score and seven years ago." Save the file with the name getty.txt. Then, using File Explorer, check the file's size. You’ll find that the file is 30 bytes in size, as each character (including spaces) uses exactly one byte. If you add more words and save the file again, the size will increase accordingly, with each new character consuming an additional byte.
If you were to examine the file from the computer's perspective, you'd see that each byte contains a number rather than a letter. This number is the ASCII code for the corresponding character (as shown below). On the disk, the file looks like this in numerical form:
F o u r a n d s e v e n 70 111 117 114 32 97 110 100 32 115 101 118 101 110
Looking up the ASCII table reveals a direct relationship between each character and its corresponding ASCII code. Notice how the space character is represented by the number 32, as it is the ASCII code for a space. We could convert these decimal numbers into binary numbers (for example, 32 = 00100000) to be more precise—this is how the computer processes the information.
The first 32 values (from 0 to 31) are reserved for control codes, such as carriage return and line feed. The space character is represented by the 33rd value, followed by punctuation, numbers, uppercase letters, and lowercase letters. To see the full range of 127 values, visit Unicode.org's chart.
Next, we'll explore byte prefixes and delve into binary mathematics.
Byte Prefixes and Binary Math
When you begin dealing with larger quantities of bytes, you start encountering prefixes such as kilo, mega, and giga, which are shorthand for kilobyte, megabyte, and gigabyte (often abbreviated as K, M, and G, or KB, MB, and GB). The following table outlines the corresponding binary multipliers:
Kilo (K)
2^10 = 1,024
Mega (M)
2^20 = 1,048,576
Giga (G)
2^30 = 1,073,741,824
Tera (T)
2^40 = 1,099,511,627,776
Peta (P)
2^50 = 1,125,899,906,842,624
Exa (E)
2^60 = 1,152,921,504,606,846,976
Zetta (Z)
2 raised to the power of 70 equals 1,180,591,620,717,411,303,424.
The term Yotta (Y) signifies this scale.
2 raised to the power of 80 is equal to 1,208,925,819,614,629,174,706,176.
In this chart, you can observe that kilo represents roughly a thousand, mega denotes about a million, giga corresponds to approximately a billion, and the sequence continues. So, when someone mentions, "This computer has a 2 gig hard drive," they’re saying the hard drive can hold 2 gigabytes, or about 2 billion bytes, or specifically 2,147,483,648 bytes. How could anyone possibly need 2 gigabytes of space? When you realize that a CD holds 650 megabytes, you can imagine that just three CDs worth of data would fill the entire drive! These days, terabyte databases are quite common, and it's likely that even petabyte databases are in use, especially at places like the Pentagon.
Binary math functions similarly to decimal math, but the value of each bit is restricted to 0 or 1. To understand binary math, let’s start with decimal addition to see how it works. For example, let’s try adding 452 and 751:
452 + 751 --- 1203
To combine these two numbers, start from the right: 2 plus 1 equals 3. Simple enough. Then, 5 plus 5 gives 10, so we keep the 0 and carry the 1 to the next place. Next, 4 plus 7 plus 1 (from the carry) gives 12, so we keep the 2 and carry the 1. Finally, 0 plus 0 plus 1 equals 1. So, the sum is 1203.
Binary addition follows the same process:
010 + 111 --- 1001
Start from the right: 0 plus 1 equals 1 for the first bit, no carry. Then, 1 plus 1 equals 10, so we keep the 0 and carry the 1. Next, 0 plus 1 plus 1 equals 10, so we save the 0 and carry the 1. For the last bit, 0 plus 0 plus 1 equals 1. Thus, the result is 1001. If you convert this back to decimal, you’ll see that 2 plus 7 equals 9.
To understand how boolean addition works with gates, check out How Boolean Logic Works.
To summarize, here’s what we've learned about bits and bytes:
- Bits are the basic units of binary data, holding a value of either 0 or 1.
- A byte consists of 8 bits.
- Binary arithmetic operates like decimal arithmetic, but each bit can only represent 0 or 1.
In the end, bits and bytes are really that straightforward.
