Absolute Difference Calculator

Enter two numbers to find how far apart they are, |a − b|.

Updated

Enter to calculate Esc to clear

Absolute Difference Calculator

Our Absolute Difference Calculator finds the distance between two numbers, |a − b|, whichever one is larger. Type the numbers and the answer appears straight away with the working, plus the signed difference, the percent difference, the percent change and the midpoint. It works with whole numbers, decimals and negative numbers, and the maths is exact, so 0.3 and 0.1 give 0.2 rather than the 0.19999999999999998 that many programs show.

Quick answer

The absolute difference is the distance between two numbers, always zero or positive: subtract one from the other and drop the minus sign. For example, |15 − 25| = |−10| = 10. Enter any two numbers above and the calculator shows the result instantly.

  • Formula: absolute difference = |a − b| = larger − smaller
  • Order: does not matter, because |a − b| = |b − a|
  • Negatives: |−20 − (−35)| = |−20 + 35| = 15
  • Excel: =ABS(A1-B1)

What Is the Absolute Difference?

The absolute difference measures how far apart two numbers are on the number line. An ordinary difference can be positive or negative depending on the order you subtract in; the absolute value removes the sign, so only the size of the gap is left.

|7 − 3| = |4| = 4
|3 − 7| = |−4| = 4

Same distance, either order.

On a number line, −10 and 5 are 15 steps apart: 10 steps from −10 up to 0, then 5 more to reach 5. That is exactly |−10 − 5| = 15.

How to Calculate It

|a − b| = a − b if a ≥ b
|a − b| = b − a if a < b

or simply: larger − smaller
  1. Subtract the second number from the first: a − b.
  2. If the answer is negative, remove the minus sign.
  3. The result is the absolute difference.

Worked Examples

ab|a − b|
1587
254015
−10515
−20−3515
7.52.35.2
−12.53.516
09999

Two negative numbers. Subtracting a negative number adds it:

|−20 − (−35)|
= |−20 + 35|
= |15| = 15

A negative and a positive number. The gap crosses zero, so the sizes add up:

|−12.5 − 3.5|
= |−16| = 16

Absolute vs Percent Difference

The same two numbers can be compared in several ways. For a = 15 and b = 25:

Measure15 and 25
Absolute difference
|a − b|
10
Signed difference
a − b
−10
Percent difference
|a − b| ÷ average × 100
50%
Percent change, a to b
(b − a) ÷ |a| × 100
+66.67%
Percent change, b to a
(a − b) ÷ |b| × 100
−40%

Use the absolute difference when the units matter (10 kg, 10 °C, 10 dollars). Use a percentage when you want to compare gaps between numbers of very different sizes: a gap of 10 is large between 15 and 25 but tiny between 10,000 and 10,010.

Properties

  • Never negative: |a − b| ≥ 0, and it is 0 only when a = b.
  • Symmetric: |a − b| = |b − a|.
  • Triangle inequality: |a − c| ≤ |a − b| + |b − c|, so a detour through b is never shorter.
  • Shift-proof: adding the same amount to both numbers does not change it: |(a + k) − (b + k)| = |a − b|.
  • Scaling: |ka − kb| = |k| × |a − b|.

Real-World Uses

  • Temperature: a night of −8 °C and a day of 12 °C differ by |−8 − 12| = 20 degrees.
  • Prices: a share that moves between 142.35 and 138.90 has a range of 3.45.
  • Tolerances: a part measuring 25.04 mm against a 25.00 mm target is 0.04 mm out.
  • Forecast errors: mean absolute error (MAE) averages |actual − predicted| over many forecasts.
  • Statistics: mean absolute deviation averages each value’s distance from the mean.
  • Images and signals: comparing two pictures pixel by pixel uses the absolute difference of brightness values.

Absolute Difference in Excel and Code

Tool|a − b|
Excel / Google Sheets=ABS(A1-B1)
Pythonabs(a - b)
JavaScriptMath.abs(a - b)
SQLABS(a - b)

Computers store most decimals in binary, so abs(0.3 - 0.1) gives 0.19999999999999998 in Python and JavaScript. Round the result, or use Python’s Decimal type, when exact decimals matter. This calculator works on the digits you type, so it shows 0.2.

Common Mistakes

  • Subtracting the absolute values. |−10| − |5| = 5, but −10 and 5 are 15 apart.
  • Losing a double negative. −20 − (−35) is −20 + 35 = 15, not −55.
  • Keeping the minus sign. The absolute difference is never negative.
  • Mixing it up with percent difference. A gap of 10 is 10 units, not 10%.
  • Mixing units. Convert both numbers to the same unit before subtracting.

Key Terms

Absolute value
The size of a number without its sign: |−4| = 4.
Difference
The result of a subtraction, which can be negative.
Distance
How far apart two points are; on a number line, |a − b|.
Midpoint
The number halfway between a and b: (a + b) ÷ 2.
MAE
Mean absolute error, the average absolute difference between forecasts and actual values.

How to Use the Absolute Difference Calculator

  1. Enter the two numbers. Type the first number a and the second number b, for example 15 and 25. Whole numbers, decimals and negative numbers all work, and the order does not matter.
  2. Read the absolute difference. The result |a − b| appears as you type, with the working underneath (for example |15 − 25| = |−10| = 10). The table below it shows the signed difference, which number is larger, the percent difference, the percent change from a to b and the midpoint.
  3. Copy the result. Press Copy to copy the absolute difference. Press Clear or Esc to start again.

Example: enter −20 and −35 and the result is 15, with the working |−20 − (−35)| = |15| = 15, a midpoint of −27.5 and the note that a is larger by 15.

Who Can Use This Calculator?

Students and TeachersAbsolute value, number lines and negative number practice
AnalystsGaps between prices, budgets, targets and actual results
Data ScientistsForecast errors, MAE and deviations from the mean
EngineersTolerances, measurement errors and signal comparisons

Frequently Asked Questions (FAQs)

What is the absolute difference?

The absolute difference between two numbers is how far apart they are, ignoring which one is bigger. It is written |a − b|: subtract one number from the other and drop any minus sign. The absolute difference between 15 and 25 is |15 − 25| = |−10| = 10.

How do you calculate the absolute difference?

Subtract the smaller number from the larger one. Equivalently, subtract in either order and take the absolute value: |a − b|. For 7.5 and 2.3 the answer is 7.5 − 2.3 = 5.2.

Can the absolute difference be negative?

No. An absolute value is never negative, so |a − b| is always 0 or more. It is 0 only when the two numbers are equal.

Does the order of the numbers matter?

No. |a − b| and |b − a| are always equal, because a − b and b − a differ only in sign. |3 − 7| = |−4| = 4 and |7 − 3| = 4.

How do you find the absolute difference of negative numbers?

Subtract carefully, remembering that taking away a negative number adds it. For −20 and −35: |−20 − (−35)| = |−20 + 35| = 15. For −10 and 5: |−10 − 5| = |−15| = 15, the distance from −10 up to 5 on the number line.

Is |a − b| the same as |a| − |b|?

No. For −10 and 5, |a − b| = 15, the real distance between them, while |a| − |b| = 10 − 5 = 5. The two match only when both numbers have the same sign and a is the larger in size. In general |a − b| is at least ||a| − |b||.

What is the difference between absolute difference and percent difference?

The absolute difference is the gap in the same units as the numbers: 15 and 25 differ by 10. The percent difference compares that gap to the average of the two numbers: 10 ÷ 20 × 100 = 50%. Percent change instead compares it to the starting value: from 15 to 25 is a 66.67% increase, while from 25 to 15 is a 40% decrease.

What are mean absolute error and mean absolute deviation?

Both are averages of absolute differences. Mean absolute error (MAE) averages |actual − predicted| over a set of forecasts: for actual values 3, 5, 2, 7 and predictions 2.5, 5, 4, 8 it is (0.5 + 0 + 2 + 1) ÷ 4 = 0.875. Mean absolute deviation averages each value’s distance from the mean: for 2, 4, 6, 8 (mean 5) it is (3 + 1 + 1 + 3) ÷ 4 = 2.

How do you calculate absolute difference in Excel?

Use =ABS(A1-B1). It works for negative numbers and decimals and gives the same answer whichever cell you put first. Fill it down a column to compare two lists row by row.

Is the Absolute Difference Calculator free?

Yes. It is completely free, needs no sign-up, and can be used as many times as you like.

Try our Absolute Difference Calculator to find the distance between any two numbers instantly.