A Beginner's Guide to Binary

Binary is the expression of numbers in the base-2 system – in contrast to the base-10 (decimal) system that we are familiar with. Whereas each 'place', or digit, in decimal (base-10) counting can take one of ten values (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), in binary (base-2) each digit can only take one of two values (0 or 1). We call each digit in a binary number a bit – an abbreviation for binary digit.

Having only two states for a digit works well with digital electronics because we can represent it as being 'on' or 'off' and therefore binary is at the heart of all modern computers (from servers to smartwatches).

Because each place can only be a one or a zero, place values are different in binary to what they are in decimal. The positional value in decimal increases in powers of 10: 1, 10, 100, 100 whereas in binary it increases in powers of 2: 1, 2, 4, 8, 16, 32.

When we have a number made up of several bits, we evaluate them using place value in a way that is similar to how we treat decimal numbers.

Decimal Place Value

For the decimal number 3258.

| 1000 | 100 | 10 | 1 |

   3      2     5   8

Total value (in decimal): (3 x 1000 + 2 x 100 + 5 x 10 + 8 x 1) = 3258

Binary Place Value

For the binary number 10111.

| 16 | 8 | 4 | 2 | 1 |

   1   0   1   1   1

Total value (in decimal): (1 x 16 + 0 x 8 + 1 x 4 + 1 x 2 + 1 x 1) = 23

Bits and Bytes

In computer science, we often talk about the size of a value in terms of the number of bits. Each bit of that number could be set to one or zero to give us the full range of values possible. A value which has 8 bits is referred to as a byte. A value with 4 bits it is a nibble – half the size of a bit.

Example

For example, an eight-bit number (a byte) could take all values possible between a minimum where all bits are set to zero and a maximum where all values are set to one. The number of different values an eight-bit number can take is 2 to the power 8, or 256: values from 0 to 255.

Minimum

| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
   0     0    0    0   0   0   0   0

Maximum

| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
   1     1    1    1   1   1   1   1

Value: 128 + 64 + 32 + 16 + 8 + 4 + 2 +1 = 255

Key Values

        | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
   254     1     1    1    1   1   1   1   0
   252     1     1    1    1   1   1   0   0
   248     1     1    1    1   1   0   0   0
   240     1     1    1    1   0   0   0   0
   224     1     1    1    0   0   0   0   0
   192     1     1    0    0   0   0   0   0
   128     1     0    0    0   0   0   0   0

Binary Notation

In many cases, texts won't use explicit notation for binary – if you see a number which is just ones and zeros then you should be able to work out from the context if it is a binary number. Other times, binary values are explicitly denoted with suffixes such as 'binary', 'b' or 'B' and other times with a prefix such as 'bin' or '0b'. In some cases, the notation 'nb' is used as a prefix where 'n' gives the number of bits – for example, 8b to denote an eight-bit value (e.g. 8b10110100).

References

Introduction to number systems and binary

Khan Academy

Follow On Cyber Learning

lesson

A Beginner's Guide to Binary

Binary is just another way of counting. Instead of using base-10 (decimal), we use base-2 where each place value is a bit.

lesson

The Complete Guide to IPv4 Subnetting

Learn how to design subnets and calculate the number of hosts on each.

Related Training Courses

course

Computer Networking Foundations

Understand how modern computer networks work.