How to Add and Subtract Hexadecimal Numbers (With Offsets and Masks)

Add, subtract and multiply hex numbers by hand with carries and borrows, then use hex for memory offsets, sizes and bit masks. Worked examples you can check.

Updated September 29, 2026 7 min read

Use the free Hex CalculatorHexadecimal arithmetic, bitwise logic and hex ↔ decimal ↔ binary conversion

Hexadecimal turns up whenever people work close to the hardware: memory addresses in a debugger, byte offsets in a file format, register values in a datasheet, permission bits and network masks. Converting everything to decimal, doing the sum, and converting back works, but it is slow and error-prone. Doing the arithmetic directly in base 16 is quicker once you know the rules.

This guide shows how to add, subtract and multiply hex numbers by hand, how to use hex arithmetic for everyday tasks like offsets and buffer sizes, and how bit masks work when they are written in hex. For converting between bases, see How to Convert Between Binary, Decimal and Hex by Hand; this guide assumes you can read a hex digit.

Hex digits and why programmers use them

Base 16 needs sixteen digits: 0 to 9, then A (10), B (11), C (12), D (13), E (14) and F (15). Each hex digit represents exactly four bits, so two hex digits describe one byte (00 to FF, or 0 to 255). That neat mapping is the whole reason hex is popular: 0xFFFF is obviously 16 bits of ones, whereas the decimal equivalent, 65,535, hides the pattern.

The 0x prefix, used in C, JavaScript, Python and many other languages, simply marks a number as hex. 0x1A3F and 1A3Fh (an older assembler style) mean the same value, 6,719.

Adding hex numbers

Add column by column from the right. When a column's total reaches 16 or more, write the total minus 16 and carry 1.

Example: 4F + 3A

  1. Right column: F + A = 15 + 10 = 25. That is 16 + 9, so write 9 and carry 1.
  2. Left column: 4 + 3 + 1 (carry) = 8. Write 8.

The answer is 0x89. Check in decimal: 79 + 58 = 137, and 8 × 16 + 9 = 137.

It helps to memorise that a column total of 16 is "10" in hex. Any digit pair whose decimal sum is between 16 and 30 produces a carry.

A longer example: 1A3F + 2B

 carry       1
         1 A 3 F
       +     2 B
       ---------
         1 A 6 A

F + B = 26 = 16 + 10, so write A and carry 1. Then 3 + 2 + 1 = 6. The upper digits are copied. The result 0x1A6A is 6,762, which matches 6,719 + 43.

Subtracting hex numbers

When a digit on top is smaller than the one below, borrow 1 from the column to the left. A borrowed 1 is worth 16 in the current column (not 10).

Example: 52 − 2E

  1. Right column: 2 − E is not possible, so borrow. The 2 becomes 2 + 16 = 18, and 18 − 14 = 4.
  2. Left column: the 5 has lent 1 and is now 4. 4 − 2 = 2.

The answer is 0x24 (82 − 46 = 36, and 2 × 16 + 4 = 36).

Checking a subtraction is easy: add the answer back to the smaller number. 0x2E + 0x24 should return 0x52, and it does.

Multiplying hex numbers

Hex multiplication uses the same long-multiplication layout as decimal, with partial products for each digit of the multiplier. 1A3F × 2B:

  • 1A3F × B = 0x120B5
  • 1A3F × 2 = 0x347E, shifted one hex place left = 0x347E0
  • 0x120B5 + 0x347E0 = 0x46895

In decimal that is 6,719 × 43 = 288,917. Multiplying by hand needs a hex times table, so this is where a calculator saves the most time. Multiplying by 0x10 is the exception: it simply appends a 0, just as multiplying by 10 does in decimal.

Practical uses

Memory and file offsets

If a data structure starts at address 0x7FF0 and a field is 0x24 bytes in, the field lives at 0x7FF0 + 0x24 = 0x8014. Notice the carry ripples: F0 + 24 = 114, so the lower byte is 14 with a carry into the upper byte.

To find the distance between two addresses, subtract them. From 0x1A3F to 0x2000 is 0x2000 − 0x1A3F = 0x5C1 bytes, or 1,473 in decimal.

Sizes and alignment

Memory and storage sizes are often round numbers in hex: 0x100 is 256, 0x400 is 1,024 and 0x1000 is 4,096. Checking whether an address is aligned to 0x1000 means checking that its last three hex digits are zero.

Bitwise operations and masks in hex

Because each hex digit is four bits, bitwise logic is easy to do digit by digit once you can picture the bits. With A = 0xF0F0 and B = 0x0FF0:

Operation Rule Result
A AND B 1 where both bits are 1 0x00F0
A OR B 1 where either bit is 1 0xFFF0
A XOR B 1 where the bits differ 0xFF00

Masks use these rules to isolate or change parts of a value:

  • Extract the low nibble: 0x3C AND 0x0F = 0x0C.
  • Extract the high nibble: shift right by 4, so 0x3C becomes 0x03.
  • Network address: the IP address 192.168.1.1 is 0xC0A80101. ANDing with the mask 255.255.255.0 (0xFFFFFF00) gives 0xC0A80100, which is 192.168.1.0. The IP Subnet Calculator does this for any address and prefix length.
  • Permissions: Unix permission bits are usually written in octal rather than hex, but the masking idea is identical; the Chmod Calculator shows the bits behind 755 or 644.

Using the Hex Calculator

The Hex Calculator has three tabs.

  1. Hex arithmetic (+ − × ÷): enter the First number (hex), choose the Operation and enter the Second number (hex). Addition shows column working with the carry row, multiplication shows each partial product, and division returns the quotient and remainder. The result is also shown in decimal, binary and octal. Numbers can be any length and may have a leading minus sign; spaces and underscores are ignored.
  2. Convert hex ↔ decimal ↔ binary: choose what the Input is written in (hex, decimal, binary or octal) and type the Number. Prefixes such as 0x, 0b and 0o are accepted. You get all four bases, the number of bytes needed to store the value, and step-by-step working.
  3. Bitwise (AND, OR, XOR…): choose a bit width and operation, including NOT, NAND, NOR and shifts, and see the result bit by bit with signed and unsigned readings.

For binary sums and two's complement, the Binary Calculator uses the same engine in base 2.

Other ways to do hex arithmetic

  • Operating system calculators in programmer mode (Windows Calculator and the macOS Calculator) handle hex arithmetic and bitwise operations in fixed widths, which is handy when you want to see overflow behaviour.
  • A programming console is often the fastest option if you have one open: hex(0x7FF0 + 0x24) in Python or (0x7FF0 + 0x24).toString(16) in JavaScript.
  • Spreadsheets offer HEX2DEC and DEC2HEX, so you can convert, calculate in decimal and convert back. That is fine for a column of values but clumsy for single sums.
  • Convert first: the Number Base Converter is useful when you need a value in several bases at once.

Common mistakes

  • Carrying at 10 instead of 16. 8 + 8 in hex is 10 (sixteen), not 16.
  • Borrowing 10 instead of 16. A borrow adds sixteen to the current digit.
  • Confusing the letter O with zero or I with 1 when copying values from a screen. Hex only uses A to F.
  • Dropping leading zeros in masks. 0x0FF0 and 0xFF0 are the same number, but when you line up digits for bitwise work, keep the full width so columns match.
  • Forgetting signedness. 0xFF is 255 as an unsigned byte but −1 as a signed 8-bit value.

Frequently asked questions

What is F + 1 in hex?

It is 0x10, which equals 16 in decimal. The F column rolls over to 0 and carries 1, exactly as 9 + 1 becomes 10 in decimal.

How do I subtract a larger hex number from a smaller one?

Subtract the smaller from the larger and put a minus sign in front, as in decimal. In fixed-width computer arithmetic, the result is instead stored in two's complement.

Why are memory addresses shown in hex?

Each hex digit maps to exactly four bits, so addresses, byte boundaries and alignment are much easier to see than in decimal.

How many hex digits are in a byte?

Two. One byte is 8 bits and each hex digit carries 4 bits, so a byte ranges from 00 to FF.

Can hex numbers have a fractional part?

Yes, in principle, with digits after a point worth 1/16, 1/256 and so on, but they are rare in practice. Most hex calculators, including ours, work with whole numbers.

Try it now: Hex Calculator

Loading tool…