A number system is a set of rules for writing numbers with symbols. We use the decimal system (also called base 10 or denary) with the ten digits 0 to 9. It is a place value system: what a digit is worth depends on its place. In 505 the first 5 means five hundred and the second only five. The same idea works with any number of digits, and it is the basis of computers, color codes on the web and many ancient cultures.
This page explains how the base 10 system really works, how to count and calculate in binary (base 2) with just 0 and 1, and how octal (base 8) and hexadecimal (base 16) fit in. You learn to convert binary to decimal, decimal to binary, hexadecimal to binary and decimal, and octal to decimal, with conversion tables, binary addition, subtraction and multiplication, negative binary numbers and exercises with answers.
The decimal system: base 10 and place value
Imagine counting 237 matchsticks. You bundle ten into a pack and ten packs into a box. You end up with 2 boxes (hundreds), 3 packs (tens) and 7 single sticks (ones, also called units). This bundling is the heart of every place value system: as soon as you have ten of something, you swap them for one of the next higher place. Why ten? Probably because we have ten fingers. Nothing forces it.
Each place value is a power of ten: ones 100 = 1, tens 101 = 10, hundreds 102 = 100 and thousands 103 = 1,000. So 3,205 means 3 · 1,000 + 2 · 100 + 0 · 10 + 5 · 1. The zero matters because it keeps the tens place empty, so the other digits stay where they belong. Without it, 3,205 would look like 325.
Types of number systems: additive and place value
Not every system uses place values. In additive systems each symbol always has the same value and you add them up. Roman numerals are one example: XIV is 10 + (5 − 1) = 14. Egyptian numerals are another, where each power of ten has its own picture. Such systems have no zero and are clumsy for written arithmetic. Positional systems need only a few digits for any number. The table shows the bases you meet most often.
| Base | Name | Digits | Where you find it |
|---|---|---|---|
| 2 | Binary | 0, 1 | Computers and digital electronics |
| 8 | Octal | 0 to 7 | File permissions on Unix and Linux |
| 10 | Decimal (denary) | 0 to 9 | Everyday life |
| 12 | Duodecimal | 0 to 9, plus two more symbols | Dozens and gross, 12 inches in a foot |
| 16 | Hexadecimal | 0 to 9, A to F | Color codes, memory addresses |
| 20 | Vigesimal | 0 to 19 | Maya; traces in French and Danish number words |
| 60 | Sexagesimal | 0 to 59 | Babylonians, clocks and angles |
The system we use today is the Hindu-Arabic numeral system, which came from India. Its history, the rules for the zero and the difference between the international and the Indian way of grouping digits are on that page.
The binary system: counting with 0 and 1
The binary number system has base 2 and only the digits 0 and 1. It matches circuits that tell two states apart: current flows or does not flow, a switch is on or off. A single binary digit is called a bit, short for “binary digit.”
Counting in binary
You count as in the decimal system, but you bundle already at two. After 1 comes 10 (read “one zero”), not 2, because two ones make one two. The place values are the powers of two.
| Power | Value | Power | Value |
|---|---|---|---|
| 20 | 1 | 29 | 512 |
| 21 | 2 | 210 | 1,024 |
| 22 | 4 | 211 | 2,048 |
| 23 | 8 | 212 | 4,096 |
| 24 | 16 | 213 | 8,192 |
| 25 | 32 | 214 | 16,384 |
| 26 | 64 | 215 | 32,768 |
| 27 | 128 | 216 | 65,536 |
| 28 | 256 |
Binary to decimal
Write the place values above the digits and add the values of the places that hold a 1. Take 1011012:
So 1011012 = 32 + 8 + 4 + 1 = 45. The zeros add nothing. More examples: 11012 = 8 + 4 + 1 = 13, and 111111112 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, the largest number that fits in 8 bits.
| Binary | Decimal | Binary | Decimal |
|---|---|---|---|
| 101 | 5 | 11001 | 25 |
| 110 | 6 | 11110 | 30 |
| 1001 | 9 | 11111 | 31 |
| 1010 | 10 | 100000 | 32 |
| 1011 | 11 | 1111111 | 127 |
| 10011 | 19 | 11111111 | 255 |
| 10101 | 21 |
Decimal to binary
There are two methods, and both give the same answer. Take 45 as the example.
Method 1: repeated division by 2. Divide the number by 2 again and again and write down each remainder (0 or 1). Stop when the quotient is 0. Read the remainders from bottom to top.
| Division | Quotient | Remainder |
|---|---|---|
| 45 : 2 | 22 | 1 |
| 22 : 2 | 11 | 0 |
| 11 : 2 | 5 | 1 |
| 5 : 2 | 2 | 1 |
| 2 : 2 | 1 | 0 |
| 1 : 2 | 0 | 1 |
Read from bottom to top, the remainders give 101101, so 45 = 1011012.
Method 2: subtract the largest power of two. Go through the powers of two from the largest downward. If one fits, write 1 and subtract it, otherwise write 0. For 77 with 64, 32, 16, 8, 4, 2, 1: 64 fits (rest 13), 32 and 16 do not, 8 fits (rest 5), 4 fits (rest 1), 2 does not, 1 fits. That gives 10011012. Check: 64 + 8 + 4 + 1 = 77. Method 2 suits small numbers, method 1 also works for large ones.
| Decimal | Binary | Octal | Hex | Decimal | Binary | Octal | Hex |
|---|---|---|---|---|---|---|---|
| 6 | 110 | 6 | 6 | 31 | 11111 | 37 | 1F |
| 9 | 1001 | 11 | 9 | 50 | 110010 | 62 | 32 |
| 12 | 1100 | 14 | C | 64 | 1000000 | 100 | 40 |
| 13 | 1101 | 15 | D | 78 | 1001110 | 116 | 4E |
| 14 | 1110 | 16 | E | 100 | 1100100 | 144 | 64 |
| 15 | 1111 | 17 | F | 123 | 1111011 | 173 | 7B |
| 16 | 10000 | 20 | 10 | 127 | 1111111 | 177 | 7F |
| 17 | 10001 | 21 | 11 | 128 | 10000000 | 200 | 80 |
| 18 | 10010 | 22 | 12 | 150 | 10010110 | 226 | 96 |
| 20 | 10100 | 24 | 14 | 200 | 11001000 | 310 | C8 |
| 22 | 10110 | 26 | 16 | 224 | 11100000 | 340 | E0 |
| 23 | 10111 | 27 | 17 | 240 | 11110000 | 360 | F0 |
| 24 | 11000 | 30 | 18 | 255 | 11111111 | 377 | FF |
| 29 | 11101 | 35 | 1D | 256 | 100000000 | 400 | 100 |
Adding binary numbers
You add column by column, as in written addition, but there are fewer rules. A column holds at most three ones (two digits and a carry).
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 1 = 10 (write 0, carry 1)
- 1 + 1 + 1 = 11 (write 1, carry 1)
Subtracting and multiplying binary numbers
Subtracting works like written subtraction with borrowing. A borrowed 1 from the next place is worth 2 in the place you borrow it for. Example: 101102 − 10112 = 10112. Check: 22 − 11 = 11.
Multiplying is the easiest of all, because you only multiply by 0 or 1 and then shift and add. For 1012 · 112 write 101 once for each 1 in 11, shifted one place: 101 + 1010 = 11112. Check: 5 · 3 = 15. Another example: 11012 · 1012 = 1101 + 110100 = 10000012, which is 13 · 5 = 65.
Negative binary numbers: signed and unsigned
A computer has no minus sign, so it uses a fixed number of bits. With 8 unsigned bits you can store 0 to 255. For signed numbers, the usual method is the two’s complement: the leftmost bit tells the sign (1 means negative), and 8 bits cover −128 to 127.
Binary fractions
Places to the right of the point are worth 1/2, 1/4, 1/8 and so on. So 0.1012 = 1/2 + 1/8 = 0.625. To convert a decimal fraction, multiply it by 2 again and again and write down the whole part: 0.375 · 2 = 0.75 (digit 0), 0.75 · 2 = 1.5 (digit 1), 0.5 · 2 = 1.0 (digit 1). So 0.375 = 0.0112. Many fractions never end in binary. 0.1 is one of them, which is why a computer shows 0.1 + 0.2 as 0.30000000000000004.
The hexadecimal system: base 16
Binary numbers are long and hard to read: 255 needs eight places, 111111112. So computer scientists like the hexadecimal number system with base 16. It needs sixteen digits. Because our alphabet of digits stops at 9, the letters A to F stand for 10 to 15.
| Hex | Decimal | Binary | Hex | Decimal | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | A | 10 | 1010 |
| 3 | 3 | 0011 | B | 11 | 1011 |
| 4 | 4 | 0100 | C | 12 | 1100 |
| 5 | 5 | 0101 | D | 13 | 1101 |
| 6 | 6 | 0110 | E | 14 | 1110 |
| 7 | 7 | 0111 | F | 15 | 1111 |
The place values are powers of 16: 1, 16, 256, 4,096 and so on.
Hexadecimal to decimal
Multiply each digit by its place value and add. These are the usual examples:
- 2F16 = 2 · 16 + 15 = 47
- A316 = 10 · 16 + 3 = 163
- 1A416 = 1 · 256 + 10 · 16 + 4 = 420
- FF16 = 15 · 16 + 15 = 255
Decimal to hexadecimal
Use repeated division by 16. For 300: 300 : 16 = 18 remainder 12 (that is C), 18 : 16 = 1 remainder 2, 1 : 16 = 0 remainder 1. Read from bottom to top: 1, 2, C. So 300 = 12C16. Check: 256 + 2 · 16 + 12 = 300.
Binary to hexadecimal and back
Here is the big advantage: one hexadecimal digit equals exactly four bits, because 24 = 16. You can switch between binary and hexadecimal without calculating. Split the binary number into groups of four from the right and replace each group using the table above.
A byte has 8 bits and can take 28 = 256 values (0 to 255). That is why it is written with exactly two hexadecimal digits, from 00 to FF. A capital A is stored as the number 65, which is 010000012 or 4116.
Hexadecimal color codes
If you pick a color for a web page, you meet hexadecimal. A code such as #FF8800 is three bytes, three pairs of hex digits, for the amounts of red, green and blue. FF = 255 is full red, 88 = 8 · 16 + 8 = 136 is about half green and 00 is no blue. The result is a strong orange. Three bytes allow 256 · 256 · 256 = 16,777,216 colors.
The octal system: base 8
The octal number system has base 8 and the digits 0 to 7. One octal digit stands for exactly three bits, so you convert octal to binary by writing three bits per digit. You find it in Unix file permissions: 755 is 111 101 101 in binary, which means read, write and execute for the owner and only read and execute for everyone else. To convert octal to decimal, use the place values 1, 8, 64: 7558 = 7 · 64 + 5 · 8 + 5 = 493. Another example: 3778 = 3 · 64 + 7 · 8 + 7 = 255.
From decimal to octal, divide by 8. For 100: 100 : 8 = 12 remainder 4, 12 : 8 = 1 remainder 4, 1 : 8 = 0 remainder 1. So 100 = 1448.
Any other base: base 5, base 36 and more
The methods work for every base b. To convert from base b, multiply digits by powers of b and add: 12345 = 1 · 125 + 2 · 25 + 3 · 5 + 4 = 194. To convert to base b, divide by b and note the remainders. 100 in base 5: 100 : 5 = 20 remainder 0, 20 : 5 = 4 remainder 0, 4 : 5 = 0 remainder 4, so 4005. And 50 in base 3: 50 : 3 = 16 r 2, 16 : 3 = 5 r 1, 5 : 3 = 1 r 2, 1 : 3 = 0 r 1, so 12123, and 27 + 18 + 3 + 2 = 50. In base 36 you use the digits 0 to 9 and A to Z, so ZZ36 = 35 · 36 + 35 = 1,295.
Conversion table: decimal, binary, octal and hexadecimal from 0 to 32
The table lists the numbers from 0 to 32 in all four systems. Each row has its own anchor, so you can link to it, for example 24.
| Decimal | Binary | Octal | Hex | Decimal | Binary | Octal | Hex |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 17 | 10001 | 21 | 11 |
| 1 | 1 | 1 | 1 | 18 | 10010 | 22 | 12 |
| 2 | 10 | 2 | 2 | 19 | 10011 | 23 | 13 |
| 3 | 11 | 3 | 3 | 20 | 10100 | 24 | 14 |
| 4 | 100 | 4 | 4 | 21 | 10101 | 25 | 15 |
| 5 | 101 | 5 | 5 | 22 | 10110 | 26 | 16 |
| 6 | 110 | 6 | 6 | 23 | 10111 | 27 | 17 |
| 7 | 111 | 7 | 7 | 24 | 11000 | 30 | 18 |
| 8 | 1000 | 10 | 8 | 25 | 11001 | 31 | 19 |
| 9 | 1001 | 11 | 9 | 26 | 11010 | 32 | 1A |
| 10 | 1010 | 12 | A | 27 | 11011 | 33 | 1B |
| 11 | 1011 | 13 | B | 28 | 11100 | 34 | 1C |
| 12 | 1100 | 14 | C | 29 | 11101 | 35 | 1D |
| 13 | 1101 | 15 | D | 30 | 11110 | 36 | 1E |
| 14 | 1110 | 16 | E | 31 | 11111 | 37 | 1F |
| 15 | 1111 | 17 | F | 32 | 100000 | 40 | 20 |
| 16 | 10000 | 20 | 10 |
Why computers use binary
Two states can be told apart very reliably, for instance low or high voltage. With ten different voltage levels the circuits would be far more error-prone. With n bits a computer can store 2n values: 8 bits give 256, 16 bits give 65,536 and 32 bits give 4,294,967,296. To store the numbers 0 to 1,000 you need 10 bits, because 29 = 512 is too small and 210 = 1,024 is enough.
Number systems in school math: sets of numbers
In a math class, “the number system” often means the different sets of numbers, each containing the one before:
- Natural numbers 1, 2, 3, … (some books include 0, and then call them whole numbers).
- Integers …, −2, −1, 0, 1, 2, … include the negative numbers.
- Rational numbers are all fractions of integers, such as 1/2, −3/4 or 0.125. Their decimals end or repeat.
- Irrational numbers like √2 and π have decimals that never end and never repeat.
- Real numbers are all rational and irrational numbers together, every point on the number line.
- Complex numbers add the imaginary unit i with i2 = −1.
The German pages explain them in detail, starting at Zahlen und ihre Eigenschaften (in German).
A short history of number systems
Place value was invented more than once. The Babylonians counted in base 60 about 4,000 years ago, and we still use their legacy with 60 minutes in an hour and 360 degrees in a circle. The Maya used base 20 with a symbol for zero, entirely independent of the Old World. Our ten digits and the zero come from India and reached Europe through the Arab world, which the page on Hindu-Arabic numerals tells in full.
Gottfried Wilhelm Leibniz (1646–1716) described the binary system in detail. He published it in 1703 in his Explication de l’Arithmétique Binaire and pointed to the hexagrams of the Chinese I Ching. In the 19th century George Boole showed that logic can be calculated with 0 and 1. Both ideas later became the basis of digital technology.
Number words keep old counting habits, too. French says quatre-vingts, “four twenties,” for 80. Danish counts 50 to 90 in twenties: halvtreds (50) is “two and a half twenties,” tres (60) is three twenties and firs (80) is four twenties. In the 13th century, Cistercian monks even devised a system in which one single sign written on a vertical stem can show any number from 1 to 9,999.
Common mistakes
Practice problems with answers
For more practice with endless new numbers, try the number systems worksheet, and to check your results the number system converter (both interfaces are in German; you only type numbers).
Frequently asked questions
What is a number system?
A system of rules for writing numbers with symbols. In a place value system such as decimal or binary, the value of a digit depends on its place and the base of the system.
How do you convert binary to decimal?
Write the place values 1, 2, 4, 8, … above the digits and add the values wherever there is a 1. For example 1011012 = 32 + 8 + 4 + 1 = 45. See binary to decimal.
How do you convert decimal to binary?
Divide the number by 2 again and again, note the remainders and read them from bottom to top. For 45 this gives 101101. See decimal to binary.
How do you convert hexadecimal to binary?
Replace each hex digit by its four bits: D7 becomes 1101 0111. To go back, group the bits in fours from the right. See binary to hexadecimal.
What are 24, 17 and 64 in binary?
24 is 11000, 17 is 10001 and 64 is 1000000. All frequently needed numbers are in the quick table and the conversion table.
What is base 10?
Base 10 is the decimal system. It has the ten digits 0 to 9, and each place is worth ten times the place to its right: ones, tens, hundreds, thousands.
What is the difference between binary, octal and hexadecimal?
They differ in the base: 2, 8 and 16. One octal digit is three bits, one hexadecimal digit is four bits, so both are short ways to write long binary numbers.
How do you add binary numbers?
Column by column from the right: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). See adding binary numbers.
Which number systems did ancient cultures use?
Egyptians and Romans had additive systems, Babylonians used base 60, the Maya base 20. The links are Egyptian numerals, Roman numerals, Babylonian numerals and Mayan numbers.
Sources and further reading
- Encyclopaedia Britannica: Numeral and numeral systems
- MacTutor History of Mathematics: Babylonian numerals
- MacTutor History of Mathematics: Gottfried Wilhelm Leibniz
- Wikipedia: Cistercian numerals and Wiktionary: Danish numerals
- Georges Ifrah: The Universal History of Numbers: From Prehistory to the Invention of the Computer, Wiley, New York 2000.
Spotted a mistake or have a request? Send us a short message and we will take care of it.