All Tools

Absolute Difference Calculator, |a - b| and Percent

Find the absolute difference between two numbers, which is larger, and the gap as a percent of each number and of their mean. Shows the working. Free, private, runs in your browser.

Enter two numbers to see their absolute difference.


About the Absolute Difference Calculator

The Absolute Difference Calculator takes two numbers and tells you how far apart they are. Type a and b and you get the absolute difference |a - b|, the signed difference a - b, which number is larger, and the gap expressed as a percentage of a, of b and of their mean. The working is written out line by line, so you can copy it into homework, a report or a spreadsheet note.

Negative numbers, decimals, thousands separators such as 1,250.5 and scientific notation such as 1.5e3 are all accepted, and the results update as you type.

How to find the absolute difference

Steps

  1. Type the first number in Number a.
  2. Type the second number in Number b. The results appear as soon as both fields hold a number.
  3. Read the Absolute difference tile, or the working above it, for the distance between the two numbers.
  4. Check Larger number to see which of the two is bigger, and the percentage tiles to see the gap in relative terms.

The formulas

The absolute difference ignores the order of the numbers and is never negative:

∣a−b∣=∣a−b∣|a - b| = \lvert a - b \rvert

The three percentages divide that distance by a different reference value. The first two use the size (magnitude) of the number, so a percentage is never negative:

∣a−b∣∣a∣×100∣a−b∣∣b∣×100\frac{|a - b|}{|a|} \times 100 \qquad \frac{|a - b|}{|b|} \times 100

The third divides by the mean of the two numbers. It is usually called the percent difference and gives the same answer whichever number you call a:

∣a−b∣∣a+b2∣×100\frac{|a - b|}{\left| \frac{a + b}{2} \right|} \times 100

Worked examples

12 and 20

The difference is |12 - 20| = 8, and the signed difference a - b is -8, so b is larger. As percentages that is 66.6666666667% of 12, 40% of 20 and 50% of the mean, which is 16.

80 and 100

The difference is 20 either way round. Measured against 80 it is 25%, measured against 100 it is 20%, and measured against the mean of 90 it is 22.2222222222%. The same gap gives three honest answers because each one uses a different reference, so say which one you mean.

-5 and 3

The working is |-5 - 3| = 8. The mean is -1, so the percent difference is 8 / 1 x 100 = 800%. Percentages of numbers close to zero get very large quickly, which is a sign that a percentage may not be the best way to describe that gap.

Absolute difference, percent difference and percent change

These three terms are often mixed up.

  • Absolute difference is the plain distance |a - b|, in the same units as the numbers. Use it when the size of the gap matters, such as the gap between two temperatures, two prices or two test scores.
  • Percent difference divides the gap by the mean of the two values. Use it when neither value is the starting point, for example comparing two measurements of the same thing or two similar products.
  • Percent change divides by the old value and keeps the sign, so an increase and a decrease differ. Use it when one number came first, such as last year to this year. The Percentage Calculator handles percent change, increases and decreases.

When a percentage is undefined

A percentage divides by a reference value, and you cannot divide by zero. If a is 0, the "of a" tile shows "undefined (division by zero)". If a and b are opposite numbers such as -4 and 4, the mean is 0 and the percent difference is undefined. This is not an error with your input, so the other tiles still show their values.

Rounding and very large numbers

Computers store most decimals approximately, so 0.3 - 0.1 is really 0.19999999999999998 inside the machine. Results are rounded to 12 significant digits, so you see the 0.2 you expect. If the difference of two numbers is too large to represent, such as 1e308 and -1e308, the page says so instead of printing a meaningless value.

Privacy

Nothing is uploaded; every calculation runs in your browser and never leaves your device.

Related tools

To work with a whole set of values, such as their range, mean and median, use the Number List Calculator. For percent change, discounts and finding a percentage of a number, use the Percentage Calculator.

Frequently asked questions

What is the absolute difference between two numbers?

It is the distance between them on the number line, written |a - b|. You subtract one from the other and drop the minus sign, so the result is never negative and does not depend on which number comes first. For 12 and 20 the absolute difference is 8.

What is the difference between absolute difference and percent difference?

The absolute difference is the gap in the original units, such as 8 dollars or 8 degrees. The percent difference divides that gap by the mean of the two numbers and multiplies by 100, so 12 and 20 give 8 / 16 x 100 = 50%. Use the first when size matters and the second when you want a relative comparison with no starting value.

How is this different from percent change?

Percent change divides by the old value and keeps the sign, so going from 80 to 100 is an increase of 25% and going from 100 to 80 is a decrease of 20%. Percent difference is symmetric: 80 and 100 give 22.2222222222% in both directions. Use the Percentage Calculator for percent change.

Why does a percentage show undefined (division by zero)?

Each percentage divides the difference by a reference value, and a reference of zero has no result. If a is 0 the percentage of a is undefined, and if a and b are opposites such as -4 and 4 the mean is 0 so the percent difference is undefined. The other results still show.

Does it work with negative numbers and decimals?

Yes. For -5 and 3 the working is |-5 - 3| = 8. You can also type decimals, thousands separators like 1,250.5 and scientific notation like 1.5e3. Percentages use the size of each number, so they are never negative.

Why does 0.3 minus 0.1 show 0.2 and not 0.19999999999999998?

Computers store most decimal fractions as binary approximations, so the raw subtraction leaves a tiny error. The calculator rounds results to 12 significant digits, which removes that noise without changing any digit you would meaningfully use.

Is my data sent anywhere?

No. The calculation runs entirely in your browser, nothing is uploaded or stored, and the numbers you type disappear when you close the page.

Other related tools