Introduction
When a packet diagram labels a field in bits, you can do the arithmetic in the same notation. Follow a carry across a byte boundary or check how many whole groups fit in a count.
Formula and calculation
division: dividend = divisor × quotient + remainderAddition, subtraction, multiplication, and division operate on unsigned integers from 0 through 2^128−1. Division by zero and results outside that range are rejected.
- quotient · unsigned integer
- integer division result
- remainder · unsigned integer
- unprocessed portion after integer division
Method and concepts
Each binary position has twice the weight of the position to its right. In addition, 1 + 1 writes a zero and carries a one into the next column. Subtraction borrows two units from the next column. Integer division splits a total into a whole quotient and a remainder.
- Write both nonnegative integers using the digits 0 and 1. Check the order when subtracting or dividing.
- Select an operation and calculate. For division, multiply the quotient by the divisor and add the remainder to recover the first input.
Binary mathematics for network engineers diagram
- Host octet · 10101101
- AND mask · 11100000
- Network · 10100000
- OR wildcard · 10111111
Worked examples
Pack 45 items into groups of six
- Write 45 as 101101 using the weights 32 + 8 + 4 + 1. Six is 110.
- Divide 101101 by 110. The whole quotient is 111 and the remainder is 11.
- Check in decimal. Seven full groups take 42 items and leave three. An eighth group would require 48.
Binary mathematics for network engineers: Check the fourth octet of 192.0.2.173/27
- Decompose 173 into 128 + 32 + 8 + 4 + 1, giving 10101101. The fourth mask byte for /27 is 11100000, or 224.
- AND the two bytes to get 10100000, or 160. Complement 11100000 within eight bits to get wildcard 00011111, or 31.
- OR 10100000 with 00011111 to get 10111111, or 191. Count inclusively: 191 − 160 + 1 = 32, which matches 2^5 host-field patterns.
Reference table
| Binary sum | Written digit | Carry left |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + carry 1 | 1 | 1 |
Reading the result
The quotient counts complete groups. A nonzero remainder matters when you need enough containers for every item. In the example, seven containers are full and an eighth is partly filled.
Common mistakes
- Binary 10 represents two. Writing the decimal digits of an operand can silently describe a different quantity if every digit happens to be 0 or 1.
- Subtracting a larger second operand requires a signed result. This worksheet uses unsigned integers up to 128 bits.
Frequently asked questions
Why does adding one to 11111111 require nine bits?
Every one carries into the next position. The sum is 100000000, or 256. A protocol field only eight bits wide cannot hold it.
What happens with a divisor of zero?
Division requires a positive divisor. No unique quotient and remainder can be calculated for a divisor of zero.
How do shifts relate to multiplication?
For an unsigned integer, shifting left one place multiplies it by two if the result still fits. A fixed-width register can lose its top bit on overflow.
Why does 255 + 1 become 256 on paper?
The exact sum has nine bits, 100000000. An eight-bit register needs an overflow indication or a defined wrapping rule to represent that operation.
Why do binary place values double from right to left?
Binary is base two. Each position is one power of two, so moving one place left multiplies its value by two.
How many bits are in a byte?
A byte contains eight bits. The byte can represent 256 distinct patterns, from 00000000 through 11111111.
Why is a subnet mask useful in binary?
A bitwise AND between an address and a contiguous mask preserves prefix bits and clears host bits, producing the network address.
Can hexadecimal shorten an IPv6 address without changing its value?
Yes. Hexadecimal groups four bits per digit, so it is a compact way to display 128-bit values. Zero compression changes notation, not the address bits.
What does two's complement do?
It is a common fixed-width representation for signed integers. The same bit pattern has a different interpretation depending on whether it is treated as signed or unsigned.
What does a bitwise AND do to a mask and address?
Each output bit is one only where both corresponding input bits are one. With a contiguous subnet mask, this preserves the prefix bits and clears host bits.
Why must a bitwise operation specify width?
Fixed-width operations constrain results to a chosen number of bits. Without a width, leading zeroes and overflow behavior can differ between mathematical integers and machine values.
How many bits does one hexadecimal digit represent?
One hexadecimal digit represents four binary bits. Two hex digits make one byte, which is why IPv6 hextets and MAC octets are naturally written in hex.
How do I convert a small binary number to decimal?
Multiply each bit by its power-of-two place value and add the results. For example, 10110₂ is 16 + 4 + 2 = 22₁₀.
Why group binary digits into fours when writing hexadecimal?
Each hex digit maps exactly to four bits. Grouping bits this way makes long address values shorter while preserving the exact bit pattern.
What is the difference between a signed and unsigned integer?
An unsigned fixed-width value treats all bits as magnitude. A signed representation reserves patterns for negative values, often using two's complement, so the same bit string can have a different decimal interpretation.
Does integer overflow wrap automatically in every calculator?
No. Behavior depends on the implementation and chosen width. A fixed-width calculator may reject an overflow, wrap, or report a carry, so inspect its documented range.
What does a bitwise OR do?
It sets an output bit when either corresponding input bit is one. It is often used to combine bit flags, while AND isolates bits and XOR highlights differences.
Further learning and references
- ECMAScript integer arithmetic and BigInt operations
Reference source for the concepts and service described in this guide.
- RFC 791 · IPv4 header and address format
- RFC 4632 · Classless Inter-domain Routing
- RFC 1700 · Historical network data notation

