Binary-to-decimal conversion is fundamental in computing, electronics and networking. Understanding how computers represent numbers in base 2 is essential for any developer, whether for network masks, bitwise operations or understanding the internal workings of a processor.

A binary number is expressed in base 2: each digit (bit) is 0 or 1, and its actual value depends on its position. The rightmost bit is worth 2⁰ = 1, the next is worth 2¹ = 2, then 2² = 4, 2³ = 8, etc. To convert to decimal, multiply each bit by its position value and add up the results.

📐 Formula

Decimal = b₇×2⁷ + b₆×2⁶ + ... + b₁×2¹ + b₀×2⁰

📊 Reference table

Binary Decimal Detailed calculation
0001 1 1×2⁰ = 1
0010 2 1×2¹ = 2
0100 4 1×2² = 4
0111 7 1×2² + 1×2¹ + 1×2⁰ = 4+2+1
1000 8 1×2³ = 8
1010 10 1×2³ + 1×2¹ = 8+2
1111 15 8+4+2+1
10000000 128 1×2⁷
11111111 255 128+64+32+16+8+4+2+1

💡 Practical examples

Example 1: convert 1011 to decimal 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11. The binary number 1011 corresponds to 11 in decimal.
Example 2: network mask 11111111 (255) A byte of 8 bits all set to 1 equals 1×128 + 1×64 + 1×32 + 1×16 + 1×8 + 1×4 + 1×2 + 1×1 = 255. This is the value of the /8 mask in CIDR notation.
Example 3: partial IP address The binary byte 11000000 corresponds to 1×128 + 1×64 = 192. This is the first byte of the 192.168.x.x range (private network).

The other way round: convert a decimal number to binary

Converting a decimal number to binary is a basic skill in computing and digital electronics. It is necessary to understand Unix permissions (chmod 755 = 111 101 101), network addresses, bitwise operations and the internal representation of data.

The successive division by 2 method is the simplest for converting decimal to binary. Divide the number by 2 repeatedly, note the remainders (0 or 1) at each step, and read the remainders from bottom to top to get the binary representation. Alternatively, you can subtract successive powers of 2.

📐 Formula

Method: divide by 2 repeatedly → read remainders from bottom to top

📊 Reference table

Decimal Binary Verification
0 0 —
1 1 1
5 101 4+1
10 1010 8+2
15 1111 8+4+2+1
16 10000 16
42 101010 32+8+2
100 1100100 64+32+4
255 11111111 128+64+32+16+8+4+2+1

💡 Practical examples

Example 1: convert 13 to binary 13 ÷ 2 = 6 remainder 1 → 6 ÷ 2 = 3 remainder 0 → 3 ÷ 2 = 1 remainder 1 → 1 ÷ 2 = 0 remainder 1. Read remainders bottom to top: 1101. Check: 8+4+1 = 13 ✓
Example 2: Unix chmod 755 permissions 7 → 111 (rwx), 5 → 101 (r-x), 5 → 101 (r-x). chmod 755 in binary = 111 101 101: read-write-execute for owner, read-execute for others.
Example 3: represent an IP byte An IP address byte like 192: 192 = 128+64 = 11000000 in binary. Subnets and CIDR masks rely on this representation.