Binary Number System Tutorial

Bits, bytes, nibbles, and counting — from zero to understanding how your computer sees numbers

Decimal feels natural because you have ten fingers. Binary — base-2 — feels alien because no one counts with two fingers. But binary is the only number system your CPU understands. Every integer, every floating-point number, every character in this sentence is just a pattern of 0s and 1s at the hardware level. This tutorial walks you through binary from scratch, with no assumed knowledge. Open our bitwise calculator in another tab to see the binary representation of any number you type.

Positional Notation: Decimal vs Binary

In decimal (base-10), each digit position represents a power of 10. The number 7403 means 7×10³ + 4×10² + 0×10¹ + 3×10⁰ = 7000 + 400 + 0 + 3. You learned this in grade school; you just stopped saying it out loud. Binary works exactly the same way, except each position is a power of 2. The rightmost position is 2⁰ (1), then 2¹ (2), 2² (4), 2³ (8), and so on. 1101 in binary means 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13 in decimal.

Counting From 0 to 15 in Binary

Watch how the bits cascade. Each time the rightmost column overflows, it carries to the next position — just like decimal carries at 10, binary carries at 2.

DecimalBinary (4-bit)
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
101010
111011
121100
131101
141110
151111

MSB, LSB, and Data Unit Sizes

The MSB (Most Significant Bit) is the leftmost bit — it carries the largest value. In 1001, the MSB is 1 and contributes 8. The LSB (Least Significant Bit) is the rightmost bit, contributing just 1. Between these two ends, data units stack up in powers of two:

UnitBitsRange (unsigned)
Bit10–1
Nibble40–15
Byte80–255
Word (16-bit)160–65,535
DWord (32-bit)320–4,294,967,295
QWord (64-bit)640–18 quintillion

Powers of 2

Computer science runs on powers of 2. Memorize these — they appear everywhere from memory addressing to hash table sizes.

PowerValueCommon Name
2⁰1
2
4
81 byte
2⁴161 hex digit range
2⁵ → 2⁸32, 64, 128, 256byte range
2¹⁰1,0241 KiB
2¹⁶65,53616-bit range
2²⁰1,048,5761 MiB
2³²4.29 billionIPv4 address space

Binary to Decimal Conversion

Sum the powers of 2 wherever a 1 appears. For 101101: positions from right are 2⁰, 2¹, 2², 2³, 2⁴, 2⁵. Bit values: 1×2⁰ + 0×2¹ + 1×2² + 1×2³ + 0×2⁴ + 1×2⁵ = 1 + 0 + 4 + 8 + 0 + 32 = 45. When the bit pattern gets long, use our bitwise calculator — paste any binary string and get the decimal result instantly.

Decimal to Binary: Repeated Division by 2

To convert decimal 45 to binary: divide by 2 repeatedly, recording the remainder (0 or 1) each time. Read the remainders from bottom to top.

45 ÷ 2 = 22 remainder 1  (LSB)
22 ÷ 2 = 11 remainder 0
11 ÷ 2 =  5 remainder 1
 5 ÷ 2 =  2 remainder 1
 2 ÷ 2 =  1 remainder 0
 1 ÷ 2 =  0 remainder 1  (MSB)
→ Read bottom-up: 101101

Why 1 KB = 1024, Not 1000

Computers address memory with binary address lines. With N address lines, you can uniquely address 2^N locations. Early computer engineers needed a word for "roughly a thousand bytes," and 2¹⁰ = 1024 was the closest power of two. Hence 1 kilobyte = 1024 bytes, 1 megabyte = 1024² = 1,048,576 bytes. Storage manufacturers later adopted decimal prefixes (1 KB = 1000 bytes), which is why your "1 TB" hard drive shows up as 931 GB in your OS — the OS still counts in binary. The IEC introduced kibibytes (KiB), mebibytes (MiB), and gibibytes (GiB) to resolve this ambiguity, but the old usage persists.

Signed vs Unsigned: Range in N Bits

With N bits, an unsigned integer can represent 0 through 2^N − 1. An 8-bit unsigned integer ranges from 0 to 255. A signed integer using two's complement splits the range: −(2^(N−1)) through 2^(N−1) − 1. For 8 bits, that is −128 to 127. The MSB becomes the sign bit — 0 for positive, 1 for negative. This is why int8 goes from −128 to 127, not −127 to 127: two's complement has exactly one representation for zero, unlike sign-magnitude which has both +0 and −0.

// 8-bit signed range check
int8_t max = 127;   // 01111111
int8_t min = -128;  // 10000000
// Overflow: 127 + 1 = -128 (wraps around)

Binary is the foundation everything else is built on. Once you can read binary fluently, hexadecimal (next tutorial) becomes a natural shorthand, and bitwise operations stop looking like magic. Bookmark our bitwise calculator for quick conversions while you practice.