ForHosting KIT · Math

Conditional probability calculator

With P(A) of 0.5, P(B) of 0.4 and a joint probability of 0.2, P(A given B) is 0.5 and the events are independent; lower the joint to 0.1 and the result drops to 0.25, no longer independent. 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
P a
0.5
P b
0.4
Joint probability P
0.2
You get
P a given b
0.5
P a given b string
0.5
P b given a
0.4
P b given a string
0.4

Conditional probability answers a precise question: given that event B has occurred, what is the chance of event A? The definition is simple and exact—P(A given B) equals the joint probability P(A and B) divided by P(B)—but students, analysts, and product teams still make costly mistakes when they confuse the joint with a product, forget to reject a zero conditioning event, or accept inconsistent triples that violate probability bounds. This capability takes three numbers, P(A), P(B), and P(A and B), returns P(A|B) as both a floating value and a stable decimal string, optionally returns the reverse conditional P(B|A) when P(A) is positive, and states whether A and B are independent by comparing the joint to P(A) times P(B).

What conditional probability means and when independence holds

In classical probability, every event is assigned a number in the closed unit interval that respects countable additivity. The joint probability P(A and B) is the mass on the intersection of the two events. Conditioning on B renormalizes that mass to the slice where B is true: formally P(A|B) equals P(A ∩ B) divided by P(B), provided P(B) is strictly greater than zero.

Independence is a separate statement: A and B are independent if and only if the joint factors as the product of the marginals, P(A ∩ B) equals P(A) times P(B). Independence is not the same as mutual exclusivity; exclusive events with positive probability have joint zero and product positive, so they fail independence. Inputs outside those bounds are rejected because no probability space can realize them.

Together, the conditional formula, the product test, and the bound checks give a complete classroom-grade check for a three-number probability triple without requiring a full sample space model.

Practical tips, common pitfalls, and how this differs from related tools

Always verify that your joint sits inside the Fréchet interval before trusting a hand calculation: a joint larger than either marginal is impossible and usually means you mixed a conditional with a joint or misread a contingency table. When P(A) is zero, P(B|A) is undefined and returned as null; that is intentional and different from returning zero.

Do not confuse this landing with Bayes theorem calculators that take likelihoods and priors to update beliefs about a hypothesis; here you already know the joint and both marginals and only need the conditional ratio and an independence verdict. Dice-sum and geometric-distribution tools elsewhere in the kit answer different search intents (polyhedral sums and trials until first success).

Data and product analytics sanity checks

Convert reported rates (share of users with feature A among those with B) into a formal conditional and verify whether A and B factor as independent for modeling assumptions.

Risk and quality documentation

Document failure-mode conditionals in safety or QA write-ups with an explicit independence statement and rejected edge cases when the conditioning event has probability zero.

What formula does the calculator use?

P(A|B) = P(A and B) / P(B). The response also reports whether P(A and B) equals P(A)×P(B) for independence.

Why is P(B) = 0 an error?

Conditioning on an event of probability zero makes P(A|B) undefined.

When are A and B independent?

When the joint equals the product of the marginals within a tiny numeric tolerance: P(A and B) = P(A)×P(B).

What are Fréchet bounds and why can my joint be rejected?

Any valid joint must lie between max(0, P(A)+P(B)−1) and min(P(A), P(B)). Values outside that range cannot occur in any probability space and are rejected.

Is the conditional probability calculator free?

The browser tool is free and runs locally.

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/conditional-probability

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/conditional-probability \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"p_a":0.5,"p_b":0.4,"p_a_and_b":0.2}'
{
  "p_a": 0.5,
  "p_b": 0.4,
  "p_a_and_b": 0.2
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "prob.conditional_probability",
  "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.

Division by zero when P(B) is zero is rejected with invalid_input so homework and production pipelines never treat an undefined conditional as a silent zero.

What conditional probability means and when independence holds

When P(B) is zero, the conditional is undefined; this tool therefore throws invalid_input instead of inventing a number. The Fréchet–Hoeffding bounds further constrain any valid joint: it cannot be smaller than max(0, P(A)+P(B)−1) and cannot exceed min(P(A), P(B)).

How to call the API and read the JSON response

Changing the joint to 0.1 yields P(A|B)=0.25 and independent false. Send a JSON body with three required numeric fields. Field p_a is the prior probability of event A in [0, 1]; aliases pA, pa, P_A, and prob_a are accepted. Field p_b is the prior probability of event B in [0, 1]; aliases pB, pb, P_B, and prob_b map to the same meaning. Field p_a_and_b is the joint P(A and B); aliases p_ab, joint, pAandB, and intersection work interchangeably. A successful response echoes the three inputs and returns p_a_given_b (the IEEE double for P(A|B)), p_a_given_b_string for stable display, p_b_given_a and its string form when P(A) is positive (otherwise null), product_p_a_p_b and a string form of that product, independence_gap equal to the joint minus the product, a boolean independent flag, frechet_lower and frechet_upper for the feasible joint interval, plus short formula and independence_rule strings for UI captions. Classic check: P(A)=0.5, P(B)=0.4, joint=0.2 yields P(A|B)=0.5 and independent true because 0.5 times 0.4 equals 0.2. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.

Practical tips, common pitfalls, and how this differs from related tools

Prefer the independent boolean and independence_gap together—floating point can make a true product look slightly off in ad-hoc spreadsheets, while this engine uses a documented absolute epsilon so textbook fractions compare cleanly. Failed validation—missing fields, values outside [0, 1], a zero conditioning probability, or an infeasible joint—returns invalid_input and never spends prepaid balance, so exploratory scripts and classroom labs stay cheap while learners probe the edges. Use p_a_given_b_string when you need stable printed digits in reports; use the numeric field when you chain further arithmetic in code.

Homework and probability teaching labs

Give students P(A), P(B), and a joint, then check their P(A|B), independence conclusion, and Fréchet-bound reasoning against a deterministic API or free browser result.

Read the full KIT documentation →