Confusion Matrix Calculator

Enter the four cell counts of a binary classifier — true positives, false positives, false negatives, and true negatives — to build the confusion matrix and compute accuracy, precision, recall, specificity, and F1 score.

Quick Facts

Method
Standard 2x2 confusion matrix metrics
Accuracy = (TP+TN)/N, Precision = TP/(TP+FP), Recall = TP/(TP+FN), F1 = harmonic mean of precision and recall.

Your Results

Calculated
Accuracy
-
(TP+TN) / total
Precision
-
TP / (TP+FP)
Recall (sensitivity)
-
TP / (TP+FN)
Specificity
-
TN / (TN+FP)
F1 score
-
2·P·R / (P+R)

Ready

Enter your four cell counts and press Calculate.

What a confusion matrix is

A confusion matrix is a 2×2 table that summarizes how a binary classifier's predictions line up against reality. Every prediction falls into exactly one of four cells: true positives (TP) — positives correctly flagged; false positives (FP) — negatives wrongly flagged as positive (a false alarm, or Type I error); false negatives (FN) — positives the model missed (a Type II error); and true negatives (TN) — negatives correctly left alone. The four counts sum to the total number of predictions, N = TP + FP + FN + TN.

The raw four cells are more informative than any single score. From them you derive every standard performance metric, and each metric answers a different question about the same table.

The metrics this calculator computes

  • Accuracy = (TP + TN) / N. The share of all predictions that were correct. Simple, but easily fooled by class imbalance.
  • Precision = TP / (TP + FP). Of everything predicted positive, how much was actually positive. High precision means few false alarms.
  • Recall (sensitivity, true positive rate) = TP / (TP + FN). Of all real positives, how many were caught. High recall means few misses.
  • Specificity (true negative rate) = TN / (TN + FP). Of all real negatives, how many were correctly cleared.
  • F1 score = 2 · Precision · Recall / (Precision + Recall). The harmonic mean of precision and recall; it is high only when both are high, so it is a good single number for imbalanced problems.

Worked example

Suppose a medical screening test is evaluated on 200 patients: TP = 80, FP = 10, FN = 20, TN = 90. Then accuracy = (80 + 90) / 200 = 0.85 (85%), precision = 80 / (80 + 10) = 0.8889 (88.89%), recall = 80 / (80 + 20) = 0.80 (80%), specificity = 90 / (90 + 10) = 0.90 (90%), and F1 = 2 · 0.8889 · 0.80 / (0.8889 + 0.80) = 0.8421. The test catches 80% of true cases while keeping false alarms fairly low.

Why accuracy alone is dangerous

On imbalanced data accuracy hides failure. If a disease affects 1% of a population, a model that predicts "healthy" for everyone is 99% accurate but has recall = 0 — it never catches a single case. Precision, recall, specificity, and F1 expose that failure; accuracy conceals it. Always report the underlying counts alongside any headline percentage.

Frequently Asked Questions

What is the difference between precision and recall?
Precision = TP / (TP + FP) asks: of everything flagged positive, what fraction was truly positive? Recall = TP / (TP + FN) asks: of all the actual positives, what fraction did we catch? Precision punishes false alarms; recall punishes misses. Tightening a model's threshold usually raises precision but lowers recall, and vice versa — the F1 score balances the two.
Why can accuracy be misleading?
Accuracy = (TP + TN) / N counts every prediction equally, so on skewed classes it rewards a model for correctly predicting the majority class while ignoring the rare one. With 1% positives, predicting "negative" every time gives 99% accuracy and zero recall. For imbalanced data, rely on precision, recall, F1, or balanced accuracy = (recall + specificity) / 2 instead.
What is the difference between sensitivity and specificity?
Sensitivity (recall) = TP / (TP + FN) measures how well the model detects actual positives. Specificity = TN / (TN + FP) measures how well it clears actual negatives. A highly sensitive test rarely misses a real case; a highly specific test rarely raises a false alarm. Screening tests are usually tuned for high sensitivity, then confirmed by a more specific follow-up test.
Which cell is a Type I versus Type II error?
A false positive (FP) is a Type I error — rejecting a true null hypothesis, i.e. a false alarm. A false negative (FN) is a Type II error — failing to reject a false null, i.e. a missed detection. Deciding which is costlier for your application drives whether you optimize for precision or for recall.