ThisCalculator

Statistics

Specificity From a Confusion Matrix: Formula and Example

Updated · Standard formula, shown below

Specificity 80.00 %
Specificity as a proportion
0.8000
Result
True negatives (TN)
80 count
You entered
False positives (FP)
20 count
You entered

Specificity From a Confusion Matrix: Formula and Example

Specificity is the share of actual negative cases that a classifier correctly predicts as negative. Enter the true-negative and false-positive counts from a confusion matrix to calculate specificity as a proportion and percentage.

Formula

Specificity = TN / (TN + FP), or Specificity (%) = 100 × TN / (TN + FP).

  • TN (true negatives): the number of actual negative cases predicted as negative; measured as a count.
  • FP (false positives): the number of actual negative cases predicted as positive; measured as a count.
  • TN + FP: the total number of actual negative cases, also called the number of negatives.

The formula divides correct negative predictions by all actual negatives. The percentage version multiplies that fraction by 100. Specificity has no physical unit; the calculator labels the percentage output with “%” and also provides the proportion.

Worked Example

Using the calculator defaults, TN = 80 and FP = 20. The total number of actual negatives is 80 + 20 = 100.

  1. Divide true negatives by all actual negatives: 80 / (80 + 20) = 80 / 100 = 0.8.
  2. Convert the proportion to a percentage: 100 × 0.8 = 80%.

The result is 80.00% specificity, or 0.8000 as a proportion. In this example, the classifier correctly identifies 80 of the 100 actual negative cases.

Reading the Confusion Matrix

A confusion matrix compares predicted classes with the cases’ actual classes. For a binary classifier, its four counts are usually arranged like this:

  • True positive (TP): actual positive, predicted positive.
  • False negative (FN): actual positive, predicted negative.
  • False positive (FP): actual negative, predicted positive.
  • True negative (TN): actual negative, predicted negative.

Specificity uses only the actual-negative row or column, depending on how the matrix is laid out: TN and FP. It does not use TP or FN. Matrix conventions differ, so check the labels rather than assuming a particular row or column represents actual cases.

For instance, if 100 cases are actually negative and 20 are wrongly labeled positive, the remaining 80 are correctly labeled negative. Specificity is 80 / 100 = 80%. The 20 false positives are included in the denominator because they are actual negatives, even though the model predicted otherwise.

When to Use Specificity

Specificity answers this question: among all actual negatives, what fraction did the classifier recognize correctly? It is useful when you need to assess how often a model avoids incorrectly flagging negative cases as positive. A higher value means fewer false positives relative to the number of actual negatives in the evaluated data.

Specificity is often considered alongside sensitivity, also called the true-positive rate. Sensitivity = TP / (TP + FN), and measures how well the system finds actual positives. The measures focus on different groups: specificity starts with actual negatives; sensitivity starts with actual positives.

Neither number alone describes all aspects of performance. A classifier can have high specificity while missing many actual positives, or high sensitivity while producing many false alarms. Which trade-off matters depends on the task and the consequences of each kind of error. Specificity is a performance measure, not a complete description of whether a classifier is suitable for a particular use.

Common Calculation Mistakes and Limits

  • Using the wrong denominator: specificity is TN / (TN + FP), not TN / (TN + FN) or TN / (TP + TN). The denominator must include every actual negative case.
  • Confusing specificity with precision: precision = TP / (TP + FP). Precision starts with predicted positives; specificity starts with actual negatives.
  • Reading the matrix without its labels: row and column order is not universal. Identify actual negatives, then find the TN and FP counts.
  • Rounding too early: keep the counts and fraction precise until the final step, then round the displayed result. A value such as 0.8 is equivalent to 80%, not 0.8%.
  • Ignoring a zero denominator: if TN + FP = 0, there are no actual negative examples in the data. Specificity is undefined, not zero; the dataset does not provide the cases needed to calculate it.

Specificity describes results on the cases included in the confusion matrix. It does not by itself establish how well a classifier will perform on other data. Results can also vary with the classification threshold: changing the cutoff for assigning the positive label may change the counts and therefore change specificity. When comparing models, use clearly defined labels and comparable evaluation data, and consider sensitivity and other relevant measures as well.

Frequently Asked Questions

How do you calculate specificity from a confusion matrix?
Divide true negatives by the sum of true negatives and false positives: TN / (TN + FP). Multiply by 100 if you want a percentage.

What is the specificity formula as a percentage?
Specificity (%) = 100 × TN / (TN + FP). For example, 80 true negatives and 20 false positives give 80% specificity.

Can specificity be calculated without false positives?
Yes, if you know TN and the total number of actual negatives, or can otherwise establish that total. Since actual negatives = TN + FP, knowing TN alone is not enough unless the number of false positives is known to be zero.

What does 100% specificity mean?
It means there were no false positives among the actual negative cases in the evaluated data. It does not show whether the classifier correctly found actual positives.

Is specificity the same as precision?
No. Specificity is TN / (TN + FP), while precision is TP / (TP + FP). Specificity concerns actual negatives; precision concerns cases predicted positive.

Related

Formula used
in tn | True negatives (TN) | count | 80 | 0
in fp | False positives (FP) | count | 20 | 0
out specificity | Specificity | % | 100 * tn / (tn + fp) | 2
out proportion | Specificity as a proportion | - | tn / (tn + fp) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.