Skip to main content
🔬 Advanced

Binary Calculator

Perform binary addition, subtraction, multiplication, and division. Convert between binary and decimal. Free math calculator. Get instant results now.

★★★★★ 4.8/5 · 📊 0 calculations · 🔒 Private & free

The Binary Number System: How Computers Count

The binary number system (base-2) uses only two digits — 0 and 1 — called bits (binary digits). Every computer, smartphone, and digital device internally stores and processes all information in binary, because electrical circuits can reliably represent two distinct states: high voltage (1) and low voltage (0).

Each position in a binary number represents a power of 2, increasing from right to left:

Position2⁷2⁶2⁵2⁴2⁰
Value1286432168421

Binary to decimal conversion: Multiply each bit by its place value and sum all results.

Example: 10110101₂ = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 1×4 + 0×2 + 1×1 = 128 + 32 + 16 + 4 + 1 = 181

Decimal to binary conversion: Repeatedly divide by 2, recording the remainder at each step, then read remainders from bottom to top.

Example: Convert 181 to binary:

Read remainders bottom to top: 10110101₂

Binary Arithmetic: Addition, Subtraction, and Multiplication

Binary arithmetic follows the same rules as decimal, but carries happen at 2 instead of 10.

Binary addition rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (carry 1), 1+1+1=11 (carry 1)

Example: 1011₂ + 1101₂ (11 + 13 = 24)

  1011
+ 1101
------
 11000

Working right to left: 1+1=10 (write 0, carry 1); 1+0+1=10 (write 0, carry 1); 0+1+1=10 (write 0, carry 1); 1+1+1=11 (write 1, carry 1); final carry writes 1. Result: 11000₂ = 24 ✓

Two's complement (binary subtraction): Computers handle negative numbers and subtraction using two's complement representation. To find the two's complement of a number: flip all bits, then add 1.

Example: −13 in 8-bit two's complement: +13 = 00001101₂ → flip all bits → 11110010₂ → add 1 → 11110011₂

This allows subtraction to be performed as addition: 20 − 13 = 20 + (−13).

Binary multiplication is elegant: each partial product is either 0 (multiplying by 0) or the number itself (multiplying by 1), shifted left. Example: 1011₂ × 101₂ (11 × 5 = 55):

    1011
  ×  101
  -----
    1011    (1011 × 1)
   0000     (1011 × 0, shifted)
  1011      (1011 × 1, shifted twice)
  -------
  110111₂ = 55 ✓

Binary in Computing: Bits, Bytes, and Data Sizes

Understanding binary units is essential for anyone working with computers, storage, or network speeds:

UnitSizeMaximum Value (unsigned)Common Use
Bit1 binary digit1Boolean flag, single binary value
Nibble4 bits15 (hex: F)One hexadecimal digit
Byte8 bits255Single character (ASCII), color channel
Word16 bits65,535Legacy 16-bit systems, Unicode basic
Double Word (DWORD)32 bits4,294,967,29532-bit integers, IPv4 addresses
Quad Word (QWORD)64 bits18,446,744,073,709,551,615Modern integers, pointers, timestamps

Color values: Web colors use 24-bit RGB (8 bits per channel). #FF5733 = R:255, G:87, B:51. Each 8-bit channel can represent 256 shades (0–255). Total possible colors: 256³ = 16,777,216 (about 16.7 million).

File permissions in Unix/Linux: rwxr-xr-- = 111 101 100 in binary = 7, 5, 4 in octal = chmod 754. Each set of 3 bits represents read (r=4), write (w=2), and execute (x=1) permissions for owner, group, and others.

Bitwise Operations and Their Applications

Bitwise operations manipulate individual bits within integers. They are fundamental to low-level programming, cryptography, network programming, and performance-critical code.

OperationSymbolBehaviorExample
AND&1 if BOTH bits are 11010 & 1100 = 1000
OR|1 if EITHER bit is 11010 | 1100 = 1110
XOR^1 if bits are DIFFERENT1010 ^ 1100 = 0110
NOT~Flip all bits~1010 = 0101
Left Shift<<Shift bits left (×2 each shift)1011 << 1 = 10110 (×2)
Right Shift>>Shift bits right (÷2 each shift)1011 >> 1 = 0101 (÷2)

Practical uses:

Number Systems Comparison: Binary, Octal, Decimal, Hexadecimal

Computer science uses four number systems, each suited to different contexts:

SystemBaseDigitsCommon Use
Binary (base-2)20, 1CPU operations, storage, logic
Octal (base-8)80–7Unix file permissions, older systems
Decimal (base-10)100–9Human-readable numbers
Hexadecimal (base-16)160–9, A–FMemory addresses, color codes, machine code

Quick conversion: binary ↔ hex (4 binary digits = 1 hex digit):

BinaryHexDecimalBinaryHexDecimal
000000100088
000111100199
0010221010A10
0011331011B11
0100441100C12
0101551101D13
0110661110E14
0111771111F15

This 4-bit grouping makes hex extremely useful as a compact notation for binary data: the 32-bit value 11001010 00111111 10110101 00001100 is much easier to write as CA3FB50C.

Binary in Networking: IP Addresses and Subnet Masks

Understanding binary is essential for network engineering because IPv4 addresses are fundamentally 32-bit binary numbers, and subnetting — the process of dividing networks — relies entirely on binary operations.

An IPv4 address like 192.168.1.100 is human-readable notation for the 32-bit binary value:

11000000.10101000.00000001.01100100

A subnet mask determines which portion of the address identifies the network and which identifies the host. The mask 255.255.255.0 in binary is:

11111111.11111111.11111111.00000000

The bitwise AND of the IP address and subnet mask gives the network address:

ComponentDecimalBinary
IP Address192.168.1.10011000000.10101000.00000001.01100100
Subnet Mask255.255.255.011111111.11111111.11111111.00000000
Network (AND)192.168.1.011000000.10101000.00000001.00000000

CIDR notation (e.g., /24) tells you how many leading 1-bits are in the subnet mask. A /24 mask has 24 ones followed by 8 zeros, allowing 2⁸ − 2 = 254 usable host addresses per subnet. A /16 mask allows 65,534 hosts. Network engineers use binary mental math daily to plan subnets, calculate broadcast addresses, and troubleshoot routing.

Binary in Cryptography and Security

Modern encryption algorithms operate entirely at the binary level, manipulating individual bits through combinations of XOR, bit shifts, and substitution operations. Understanding binary is the gateway to understanding how digital security works.

XOR encryption (the foundation of modern ciphers): XOR has a unique property — applying it twice with the same key returns the original value: A ⊕ K ⊕ K = A. This makes XOR the basis of stream ciphers and one-time pads.

Example: encrypting the byte 01001101 (letter 'M' in ASCII) with key 10110010:

Key sizes in modern encryption: AES-128 uses a 128-bit key, meaning there are 2¹²⁸ ≈ 3.4 × 10³⁸ possible keys — more than the number of atoms in the observable universe. AES-256 uses 256-bit keys with 2²⁵⁶ possibilities. Even the fastest supercomputers cannot brute-force these key spaces. Each additional bit doubles the search space, which is why key length matters exponentially in cryptography.

Hash functions like SHA-256 produce a 256-bit (32-byte) binary output from any input. Even a single bit change in the input produces a completely different hash — a property called the "avalanche effect" that makes hashes useful for verifying data integrity, storing passwords, and powering blockchain technology.

Binary and quantum computing: While classical computers use binary bits (0 or 1), quantum computers use qubits that can exist in a superposition of both states simultaneously. A classical 256-bit key has 2²⁵⁶ possible values that must be checked sequentially; a quantum computer running Grover's algorithm could search this space in √(2²⁵⁶) = 2¹²⁸ operations. This is why post-quantum cryptography is being developed — to create binary-based encryption schemes that remain secure even against quantum adversaries.

Frequently Asked Questions

Why do computers use binary instead of decimal?

Electronic circuits are most reliable with just two distinct states: on (high voltage ≈ 1) and off (low voltage ≈ 0). Representing 10 distinct states for decimal would require much more precise voltage control and would be far more susceptible to electrical noise. Binary's simplicity allows billions of transistors to operate reliably at GHz speeds with billions of operations per second.

What is the largest number a byte can hold?

A byte (8 bits) can represent 2⁸ = 256 different values. For unsigned integers: 0 to 255. For signed integers (two's complement): −128 to 127. The maximum unsigned byte value in binary is 11111111₂ = 255; in hex it's FF.

How do I convert a negative number to binary?

Use two's complement: (1) Convert the positive version to binary, (2) Flip all bits (0→1, 1→0), (3) Add 1. Example — −13 in 8-bit: +13 = 00001101₂, flip bits = 11110010₂, add 1 = 11110011₂. This is how all modern computers store negative integers.

What is the difference between binary and hexadecimal?

Both are positional number systems used in computing. Binary (base-2) uses only 0 and 1 — the native language of computers. Hexadecimal (base-16) uses 0–9 and A–F as a compact notation for binary — every 4 binary digits correspond to exactly 1 hex digit. Hex is used for memory addresses, color codes (#RRGGBB), and machine code because it's more compact and readable than raw binary.

What are bitwise operations used for?

Bitwise operations (AND, OR, XOR, NOT, shifts) manipulate individual bits within integers. Common uses: bit flags and permissions (Unix chmod), checking even/odd (n & 1), fast multiplication/division by powers of 2 (bit shifting), encryption algorithms, hash functions, CRC error detection, network subnet masks, and game development (compact state storage in a single integer).

What is binary floating point and why does 0.1 + 0.2 ≠ 0.3 in programming?

Most modern computers use IEEE 754 binary floating point, which represents decimal fractions in binary. Just as 1/3 = 0.3333... cannot be represented exactly in decimal, 1/10 cannot be represented exactly in binary (it's an infinitely repeating binary fraction). This causes tiny rounding errors: in most languages, 0.1 + 0.2 = 0.30000000000000004. Use integer arithmetic (work in cents, not dollars) or decimal libraries for exact financial calculations.

How is binary used in data storage and file sizes?

Storage is measured in bytes (8 bits), kilobytes (1,024 bytes), megabytes (1,024 KB), gigabytes (1,024 MB), etc. Note: hard drive manufacturers use SI prefixes (1 KB = 1,000 bytes) while operating systems use binary prefixes (1 KiB = 1,024 bytes), causing the apparent "missing space" discrepancy when you buy storage. A 1 TB drive shows ~931 GiB in Windows because 1,000,000,000,000 ÷ 1,073,741,824 ≈ 931.

What is binary-coded decimal (BCD)?

BCD encodes each decimal digit as a 4-bit binary group: 0=0000, 1=0001, ..., 9=1001. So decimal 93 in BCD is 1001 0011. BCD is used in financial systems (avoids floating-point rounding errors), digital clocks and displays (7-segment displays decode BCD directly), and old mainframe systems. It's less space-efficient than pure binary but eliminates decimal-to-binary conversion errors in critical applications.

},{"@type":"Question","name":"What is the largest number a byte can hold?","acceptedAnswer":{"@type":"Answer","text":"A byte (8 bits) can represent 2⁸ = 256 different values. For unsigned integers: 0 to 255. For signed integers (two's complement): −128 to 127. The maximum unsigned byte value in binary is 11111111₂ = 255; in hex it's FF."}},{"@type":"Question","name":"How do I convert a negative number to binary?","acceptedAnswer":{"@type":"Answer","text":"Use two's complement: (1) Convert the positive version to binary, (2) Flip all bits (0→1, 1→0), (3) Add 1. Example — −13 in 8-bit: +13 = 00001101₂, flip bits = 11110010₂, add 1 = 11110011₂. This is how all modern computers store negative integers."}},{"@type":"Question","name":"What is the difference between binary and hexadecimal?","acceptedAnswer":{"@type":"Answer","text":"Both are positional number systems used in computing. Binary (base-2) uses only 0 and 1 — the native language of computers. Hexadecimal (base-16) uses 0–9 and A–F as a compact notation for binary — every 4 binary digits correspond to exactly 1 hex digit. Hex is used for memory addresses, color codes (#RRGGBB), and machine code because it's more compact and readable than raw binary."}},{"@type":"Question","name":"What are bitwise operations used for?","acceptedAnswer":{"@type":"Answer","text":"Bitwise operations (AND, OR, XOR, NOT, shifts) manipulate individual bits within integers. Common uses: bit flags and permissions (Unix chmod), checking even/odd (n & 1), fast multiplication/division by powers of 2 (bit shifting), encryption algorithms, hash functions, CRC error detection, network subnet masks, and game development (compact state storage in a single integer)."}},{"@type":"Question","name":"What is binary floating point and why does 0.1 + 0.2 ≠ 0.3 in programming?","acceptedAnswer":{"@type":"Answer","text":"Most modern computers use IEEE 754 binary floating point, which represents decimal fractions in binary. Just as 1/3 = 0.3333... cannot be represented exactly in decimal, 1/10 cannot be represented exactly in binary (it's an infinitely repeating binary fraction). This causes tiny rounding errors: in most languages, 0.1 + 0.2 = 0.30000000000000004. Use integer arithmetic (work in cents, not dollars) or decimal libraries for exact financial calculations."}},{"@type":"Question","name":"How is binary used in data storage and file sizes?","acceptedAnswer":{"@type":"Answer","text":"Storage is measured in bytes (8 bits), kilobytes (1,024 bytes), megabytes (1,024 KB), gigabytes (1,024 MB), etc. Note: hard drive manufacturers use SI prefixes (1 KB = 1,000 bytes) while operating systems use binary prefixes (1 KiB = 1,024 bytes), causing the apparent \"missing space\" discrepancy when you buy storage. A 1 TB drive shows ~931 GiB in Windows because 1,000,000,000,000 ÷ 1,073,741,824 ≈ 931."}},{"@type":"Question","name":"What is binary-coded decimal (BCD)?","acceptedAnswer":{"@type":"Answer","text":"BCD encodes each decimal digit as a 4-bit binary group: 0=0000, 1=0001, ..., 9=1001. So decimal 93 in BCD is 1001 0011. BCD is used in financial systems (avoids floating-point rounding errors), digital clocks and displays (7-segment displays decode BCD directly), and old mainframe systems. It's less space-efficient than pure binary but eliminates decimal-to-binary conversion errors in critical applications."}}]}