ForHosting KIT · Math

Bayes theorem calculator

With a prior of 0.01, a sensitivity of 0.99 and a false-positive rate of 0.05, a positive result leaves about a 1 in 6 chance that the hypothesis is true. Enter three probabilities and get the posterior, the evidence probability and the specificity. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Prior
0.01
True positive rate P
0.99
False positive rate P
0.05
You get
Specificity
0.95
Evidence
0.0594
Posterior
0.1666666667
Likelihood ratio positive
19.8

The Bayes theorem calculator turns a prior probability, a sensitivity (true positive rate), and a false-positive rate into the posterior probability of a hypothesis after observing evidence. This is the standard binary update used in diagnostic reasoning, quality-control alarms, spam filters sketches, and classroom problems about rare diseases and imperfect tests. You supply three numbers on the closed unit interval: how common the hypothesis is before seeing the test, how often the evidence appears when the hypothesis is true, and how often the evidence appears when the hypothesis is false. The engine returns the posterior P(H given E), the marginal evidence probability P(E), the specificity one minus the false-positive rate, and the positive likelihood ratio when it is finite.

What Bayes' rule tells you and what you get

Bayes' theorem answers a deceptively simple question: given how often a hypothesis is true before you look, and how the evidence behaves when the hypothesis is true or false, how strongly should you believe the hypothesis after you observe the evidence? In symbols, P(H given E) equals P(E given H) times P(H) divided by P(E). For a binary hypothesis the evidence probability expands as sensitivity times prior plus false-positive rate times one minus prior.

That single identity underpins the classic rare-disease example in every probability textbook: a highly accurate test can still leave a low posterior when the base rate is tiny, because false positives dominate the positive results. This calculator returns that posterior together with the intermediate evidence mass, the specificity one minus the false-positive rate, and the positive likelihood ratio sensitivity over false-positive rate when the denominator is positive. Inputs are echoed in normalized numeric form so callers can verify unit conversion did not change scale.

The contract is strict by design.

Where posterior updates fit in study, product, and operations

Students meet Bayes' theorem when a textbook asks for the chance someone has a rare condition after a positive screening test, when a worksheet wants the probability a machine is faulty after an alarm, or when they verify that base rates matter more than raw test accuracy. Teachers can pre-generate answer keys for fixed priors and test characteristics without relying on opaque calculator apps that hide the evidence expansion.

Product and security teams sketch alert fatigue: high sensitivity with a non-trivial false-positive rate and a low prior of real incidents produces moderate posteriors that justify secondary review queues rather than automatic shutdowns. Quality engineers model pass-fail gauges where a sensor fires on true defects and on occasional false alarms, then convert those rates into a posterior defect probability for a flagged unit. Data scientists use the same structure when documenting why a high-precision classifier can still yield low absolute risk in a rare-event population.

Developers call the contract from scripts to seed deterministic unit-test vectors, to illustrate likelihood ratios, or to satisfy programming challenges that demand P(H given E) for given prior, sensitivity, and false-positive rate without embedding ad-hoc formulas. Contest practice often needs a fast offline source of Bayes numbers so solutions can be checked without hand-rolling denominators under time pressure.

Diagnostic and rare-event classroom problems

Compute posterior disease or fault probability after a positive test given prevalence, sensitivity, and false-positive rate.

Alert and quality-control sketches

Translate alarm sensitivity and false-alarm rate plus base incident rate into a posterior probability for triage design.

What does the Bayes theorem calculator cost?

It is free in your browser on this page.

What happens if a probability is outside 0 to 1?

Probabilities must lie in the closed interval from zero to one.

What is the positive likelihood ratio?

It is sensitivity divided by the false-positive rate when that rate is greater than zero.

Why is the posterior low even when the test is very accurate?

Because the base rate matters. With a prior of 0.01, a sensitivity of 0.99 and a false-positive rate of 0.05, the posterior is only about 1 in 6: among all positive results, false positives from the large group without the condition outnumber true ones.

What formula does the Bayes calculator use?

The posterior equals sensitivity times prior, divided by the evidence probability. The evidence probability is sensitivity times prior plus false-positive rate times one minus prior; in the example it comes to 0.0594.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/prob/bayes-theorem

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/prob/bayes-theorem \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prior":0.01,"sensitivity":0.99,"false_positive_rate":0.05}'
{
  "prior": 0.01,
  "sensitivity": 0.99,
  "false_positive_rate": 0.05
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "prob.bayes_theorem",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Any probability outside zero to one is rejected with invalid_input rather than clamped, so bad spreadsheets and off-by-one percent values cannot silently corrupt a result. Arithmetic is pure deterministic floating-point with no network, randomness, or clock dependency, so the same triple always yields the same JSON.

What Bayes' rule answers and what the response contains

Prior, sensitivity, and false-positive rate must each lie in the closed interval from zero to one; values below zero or above one, non-finite numbers, empty strings, and non-numeric types raise invalid_input with a message that names the field. If the three numbers combine to an evidence probability of zero, the posterior is mathematically undefined and the call fails instead of returning NaN. This page is a single binary Bayes update only. It does not chain multiple independent tests, does not sample from posteriors, and does not fit hierarchical models. When you need binomial trial counts, Poisson rates, or full Bayesian networks, use those dedicated tools; here the search intent is a clear Bayes theorem calculator for prior, sensitivity, and false-positive rate with free browser execution and a priced, identical API path.

How prior, sensitivity, and false-positive rate are read and combined

Each value may arrive as a JavaScript number or as a trimmed decimal string, including scientific notation for tiny prevalences such as one in ten thousand. Leading and trailing spaces on strings are stripped; embedded junk, hex prefixes, and non-finite tokens are rejected so a corrupted cell cannot become a silent wrong posterior. The posterior is sensitivity times prior divided by that evidence mass. Specificity is returned as one minus the false-positive rate for readers who think in test-performance language rather than error rates. Tiny floating-point noise that would push the posterior slightly outside the unit interval is clamped to the closed bounds so clients never receive a probability of one plus epsilon from rounding alone. The preferred field names are prior for P(H), sensitivity for P(E given H), and false_positive_rate for P(E given not H). Aliases keep forms and scripts flexible: base_rate, prevalence, and p_h map to prior; true_positive_rate, tpr, and recall map to sensitivity; fpr, type_i_rate, and false_alarm_rate map to the false-positive rate. BigInt is accepted only for the exact endpoints zero and one. After validation the engine computes evidence as sensitivity times prior plus false_positive_rate times one minus prior. The positive likelihood ratio is sensitivity divided by false_positive_rate whenever the false-positive rate is strictly positive; when the rate is zero the field is null to avoid non-JSON Infinity values. Pair free browser runs on this page with the priced API when automation needs the identical mathematical result without re-implementing Bayes arithmetic in every language you ship.

Where posterior updates fit in study, product, and operations

On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with binomial probability tools when you need trial counts rather than hypothesis updates, and with other math endpoints when you are assembling a small lab of free, deterministic probability helpers for teaching and CI.

Deterministic test fixtures

Generate reproducible posterior, evidence, specificity, and likelihood-ratio fields for unit tests and CI without hand-rolled Bayes formulas.

What formula is used for the posterior?

P(H|E) = sensitivity × prior ÷ (sensitivity × prior + false_positive_rate × (1 − prior)). The evidence field is that denominator.

When is the posterior undefined?

If sensitivity, prior, and false_positive_rate combine so that P(E) equals zero, there is no positive evidence mass and the call returns invalid_input instead of NaN.

Read the full KIT documentation →