Bayes Theorem Calculator | Find Posterior Probability

Work from a prior probability and likelihoods to the probability of a cause after an observation.

Quick Answer

Bayes’ theorem updates a prior probability after observing evidence. Multiply the prior probability of the hypothesis by the probability of the evidence given that hypothesis, then divide by the overall probability of observing the evidence.

Two jars of coloured beads beside a probability tree
Free Probability Tool

Bayes Theorem Calculator

Use this Bayes Theorem Calculator to find posterior probability from prior probability, likelihood, and false-positive or alternative-event probability. Enter probabilities as percentages, decimals, or fractions, and get a clean step-by-step Bayes theorem solution with formulas.

Calculate Bayes Theorem

Enter the probability of event A, the probability of evidence B given A, and the probability of evidence B given not A. The calculator finds \(P(A|B)\), the updated probability of A after observing B.

Input tip: you can type probabilities as 5%, 0.05, or 1/20. Values must represent probabilities between 0 and 1.

What Is a Bayes Theorem Calculator?

A Bayes Theorem Calculator is a probability tool that updates the probability of an event after new evidence is observed. It uses Bayes theorem to calculate a posterior probability, which is the revised probability of a hypothesis after considering evidence. The calculator is useful when you know a prior probability, a likelihood, and the probability of the evidence under an alternative condition. Use the probability worksheets with answers to practise recognizing which probability model applies.

Bayes theorem is one of the most important ideas in probability, statistics, artificial intelligence, data science, medical testing, risk analysis, machine learning, spam filtering, legal reasoning, diagnostic reasoning, and decision-making. It gives a structured way to revise beliefs when new information arrives. Instead of treating evidence in isolation, Bayes theorem combines the evidence with the original base rate.

For example, suppose a medical condition is rare, but a test for it is very accurate. If someone receives a positive test result, many people assume the probability of having the condition must be almost the same as the test accuracy. Bayes theorem shows why that assumption can be wrong. If the condition is rare, false positives may still be common compared with true positives. The final posterior probability depends on the base rate, test sensitivity, and false-positive rate together.

This calculator is designed to make that reasoning visible. It calculates \(P(A|B)\), which means the probability of event A given evidence B. It also shows \(P(B)\), the total evidence probability, the true-positive part, the false-positive part, and the complement probability \(P(A^c|B)\). The step-by-step section explains every part of the calculation so students and readers can understand the result, not just copy an answer.

How to Use the Bayes Theorem Calculator

Start by entering the prior probability \(P(A)\). This is the probability of the event before the new evidence is known. For example, if 1 out of 100 people in a population has a condition, the prior probability is 1%, 0.01, or 1/100. The calculator accepts all three formats.

Next, enter the likelihood \(P(B|A)\). This is the probability of seeing the evidence if event A is true. In a medical-test example, this may be the sensitivity of the test: the probability that the test is positive when the person truly has the condition. In a spam-filter example, it may be the probability that an email contains a specific word if the email is spam.

Then enter the alternative likelihood \(P(B|A^c)\). This is the probability of seeing the same evidence when event A is not true. In a medical-test example, this is the false-positive rate: the probability that the test is positive even though the person does not have the condition. In a fraud example, this might be the chance that a normal transaction still triggers a suspicious signal.

Choose how many decimal places should appear in the result and click the calculate button. The calculator returns the posterior probability \(P(A|B)\), the probability of the evidence \(P(B)\), the complement probability, and all calculation steps. A percentage bar compares the prior and posterior probability so the update is visually clear.

Bayes Theorem Calculator Formulas

The standard Bayes theorem formula is:

Bayes theorem
\[P(A|B)=\frac{P(B|A)P(A)}{P(B)}\]

When the evidence \(B\) can occur under event A or under the complement of A, the denominator can be expanded using the law of total probability:

Evidence probability
\[P(B)=P(B|A)P(A)+P(B|A^c)P(A^c)\]

The complement of A is:

Complement probability
\[P(A^c)=1-P(A)\]

Substituting the total probability formula into Bayes theorem gives the calculator’s main formula:

Bayes theorem with complement event
\[P(A|B)=\frac{P(B|A)P(A)}{P(B|A)P(A)+P(B|A^c)P(A^c)}\]

The posterior complement can also be calculated:

Posterior complement
\[P(A^c|B)=1-P(A|B)\]

Prior, Likelihood, Evidence, and Posterior

Bayes theorem becomes easier when each term has a clear meaning. The prior probability is the starting probability before the evidence is considered. It is written as \(P(A)\). The prior may come from historical data, population frequency, previous research, expert estimates, or baseline assumptions.

The likelihood is the probability of the evidence if the hypothesis is true. It is written as \(P(B|A)\). The likelihood measures how strongly the evidence is expected under event A. Strong evidence usually has a high likelihood when A is true and a low likelihood when A is false.

The evidence probability, or marginal probability of evidence, is written as \(P(B)\). It measures how often the evidence occurs overall. In the complement version of Bayes theorem, evidence can arise from true-positive cases and false-positive cases. Both parts must be counted. Use the combinations and Pascal's triangle to count selections where order doesn't matter.

The posterior probability is the updated probability after evidence is observed. It is written as \(P(A|B)\). This is usually the answer users want from a Bayes theorem calculator. It answers, “Given that evidence B occurred, what is the probability that A is true?” Use the binomial probability calculator to check the chance of a given count of successes in independent trials.

TermNotationMeaning
Prior\(P(A)\)Probability of A before observing evidence B.
Likelihood\(P(B|A)\)Probability of evidence B if A is true.
Alternative likelihood\(P(B|A^c)\)Probability of evidence B if A is false.
Evidence\(P(B)\)Total probability that evidence B occurs.
Posterior\(P(A|B)\)Updated probability of A after observing B.

Bayes Theorem with a Complement Event

The complement form is the version most users need because many real-world problems involve two possibilities: the event happens or it does not happen. A person has a condition or does not have it. An email is spam or not spam. A transaction is fraudulent or legitimate. A student knows a concept or does not know it. A machine is defective or not defective.

In these cases, the evidence can appear in both groups. A test can be positive for someone with the condition, but it can also be positive for someone without the condition. A fraud alert can occur for a fraudulent transaction, but it can also occur for a legitimate transaction. Bayes theorem forces both pathways to be included in the denominator.

The denominator is often the most important part of the calculation. Many incorrect intuitive answers ignore the false-positive pathway. If the prior probability is low and the false-positive rate is not extremely small, the false-positive part can be large compared with the true-positive part. This is why a high test sensitivity does not automatically imply a high posterior probability when the event is rare. Use the event probability calculator to compare the formulas for different types of events.

Common Applications of Bayes Theorem

Bayes theorem appears in many fields because it is a general rule for updating probabilities. In medical testing, it helps estimate the probability that a patient has a condition after a positive or negative test result. It combines prevalence, sensitivity, and false-positive rate.

In machine learning, Bayesian reasoning helps models update predictions as new data arrives. Naive Bayes classifiers are used in text classification, spam filtering, sentiment analysis, and document categorization. In cybersecurity, Bayesian reasoning can help score alerts by combining base rates and signal patterns.

In business and marketing, Bayes theorem can update the probability that a lead will convert after a customer action. In legal and forensic reasoning, it can help explain how evidence changes probability, although it must be used carefully and ethically. In education, Bayesian updating can model whether a student has mastered a skill after answering a question correctly.

Bayes Theorem Worked Examples

Example 1: Suppose a condition affects 1% of a population. A test is positive for 99% of people who have the condition, and it is falsely positive for 5% of people who do not have the condition. We want \(P(A|B)\), the probability that a person has the condition given a positive result.

Medical-test example
\[P(A|B)=\frac{0.99\times0.01}{(0.99\times0.01)+(0.05\times0.99)}\]

The true-positive part is \(0.0099\). The false-positive part is \(0.0495\). The total evidence probability is \(0.0594\). Therefore:

Posterior result
\[P(A|B)=\frac{0.0099}{0.0594}\approx0.1667=16.67\%\]

This result often surprises people. Even with a very sensitive test, the posterior probability is only about 16.67% because the condition is rare and false positives occur among the much larger group without the condition.

Example 2: Suppose 30% of emails are spam. A certain word appears in 80% of spam emails and 10% of non-spam emails. The probability that an email is spam given that it contains the word is:

Spam-filter example
\[P(Spam|Word)=\frac{0.80\times0.30}{(0.80\times0.30)+(0.10\times0.70)}=\frac{0.24}{0.31}\approx77.42\%\]

Common Bayes Theorem Mistakes

The first common mistake is confusing \(P(A|B)\) with \(P(B|A)\). These are not the same. \(P(B|A)\) is the probability of evidence if the event is true. \(P(A|B)\) is the probability of the event after evidence is observed. Bayes theorem converts one direction into the other using the prior and evidence probability.

The second mistake is ignoring the base rate. Base rate means the original frequency of the event. If an event is rare, even strong evidence may not make the posterior probability extremely high unless the false-positive rate is very low. This is called base-rate neglect.

The third mistake is using percentages and decimals inconsistently. For example, 5% should be entered as 5%, 0.05, or 1/20, not as 5 unless the calculator explicitly treats it as a percentage. This tool accepts percentage signs to reduce that confusion.

The fourth mistake is treating Bayes theorem as proof. Bayes theorem updates probability under the assumptions entered. If the prior, likelihood, or false-positive rate is wrong, the posterior result can also be wrong. Good Bayesian reasoning depends on reliable inputs.

Bayes Theorem Calculator FAQs

What does a Bayes Theorem Calculator do?

It calculates posterior probability, usually written as \(P(A|B)\), by combining prior probability, likelihood, and evidence probability.

What is Bayes theorem?

Bayes theorem is a probability rule that updates the probability of an event after new evidence is observed: \(P(A|B)=\frac{P(B|A)P(A)}{P(B)}\).

What is prior probability?

Prior probability is the probability of an event before observing the new evidence. It is written as \(P(A)\).

What is posterior probability?

Posterior probability is the updated probability after evidence is observed. It is written as \(P(A|B)\).

Can I enter percentages?

Yes. You can enter values like 5%, 0.05, or 1/20. The calculator converts them into probability values.

Why is the posterior sometimes much lower than test accuracy?

Because the posterior depends on the base rate and false-positive rate, not just test sensitivity. Rare events can produce many false positives compared with true positives.

Important Note

This Bayes Theorem Calculator is for education, probability learning, statistics practice, and general reasoning. It is not medical advice, legal advice, financial advice, diagnostic guidance, or a substitute for expert review. Real-world decisions should use verified data, appropriate models, and qualified professional judgment where needed.

Advertisement

Use expected counts to check Bayes' rule

A game selects a blue jar twenty percent of the time and a green jar otherwise. The chance of drawing a striped bead is seventy percent in the blue jar and ten percent in the green jar. Imagine 1,000 plays. About 200 select blue, producing 140 striped beads. Of the 800 that select green, about 80 produce striped beads. Among all 220 striped outcomes, 140 came from blue. The probability of a blue jar given a stripe is therefore about 63.64 percent. The seventy percent input answers the opposite conditional question.

The Arab-Islamic Conquest Movement

Arab tribes had come together for a common cause in the pre-Islamic period, such as a war against another tribe or recognition of the strength of a chieftain. But once that cause had been accomplished or that chieftain had died, the confederacy typically disbanded, its purpose fulfilled. In the wake of Muhammad’s death, at least some Arab tribes likewise believed the community’s purpose had been completed. His accomplishment in bringing people together under the banner of Islam was not one the surviving leaders of the community intended to be temporary, however.
There were urgent questions about the leadership of the community, and immediate disagreements about it as well. In many tribal- and clan-based societies like that of the Arabs, leadership was not hereditary, meaning it did not immediately pass to the heir upon the death of the leader. Thus, as Muhammad was dying, two primary claimants for leadership emerged: his son-in-law Ali ibn Abi Talib, and a friend and confidant of Muhammad’s named Abu Bakr. Ali, related to the Prophet by blood and marriage, was comparatively young in a society that saw leadership in its elders, although he claimed to have been chosen by Muhammad as his heir and successor. Abu Bakr, in contrast, was one of the elders of the community, well respected and popularly chosen. Both had been among the first to convert to Islam.
Members of the community had concerns about their own standing. Some were the earliest converts who had joined Muhammad when he was still in Mecca, some had welcomed his community in Medina when they needed shelter, and still others had not converted until shortly before Muhammad’s death. In the end, Abu Bakr was chosen to be the first successor to Muhammad, the caliph or religious and political leader of the Muslim community. This was accomplished through popular acclamation by tribal leaders, who ultimately won out over those who favored the lineage of Ali. Islam had weathered this first hurdle, although the question of leadership had longer-term implications for the unity of the ummah. Ali, believed by some to have been chosen by Muhammad as his heir, was likely aggrieved at the decision, although he accepted it. Other stakeholders may also have felt slighted, including a number of Muhammad’s wives, several of whom were shunned despite their close relationship as members of the family of the Prophet. And while this new role of caliph would provide leadership to the young community at a critical juncture, there seems to have been near immediate recognition that things without Muhammad would be different, not least of which because the caliph was not assuming the mantle of another prophet capable of communicating directly with God as Muhammad had.
Tensions arose after Muhammad’s death not just over leadership and inheritance, but also over whether the alliance was ever intended to last beyond its founder. Some Arab tribes left to return to their homes, while others may have believed they could discard their commitment to the worship of the one God and membership in this confederation. From the perspective of the Muslims, however, this was apostasy, and a conflict known as the Ridda Wars then began in an attempt to force these Arab tribes to continue to honor their agreements with the Muslims. The Ridda Wars also appear to have been expansionist, bringing into the fold, whether by treaty or force, Arab tribes that had never been aligned with Muhammad’s community during his lifetime. This effort was the first step of a wider movement called the Arab-Islamic or Arab-Muslim conquests, and by 633 the entirety of Arabia had been brought under the control of this first Islamic state.
Abu Bakr did not live long after Muhammad, and the conquest movement did not stop with his leadership, nor with uniting just the Arab tribes under the banner of Islam. The new state’s expansionist desire seems to have existed from the outset, and the Arab-Muslim armies turned their attention northward to the old empires of Sasanian Persia and Byzantium. They were likely inspired by the richness of these lands, where they knew resources were more plentiful and luxury trade goods regularly traveled. But there were other factors, too. The Arab-Muslims may have felt emboldened by their successes in Arabia, seeing them as recognition of God’s favor and of their destiny to rule the world.
Religious belief and zeal are difficult for historians to quantify, but we have seen throughout history that nomadic and seminomadic societies must forcefully seek the resources they need to survive while defending themselves against threats that sedentary societies face less often. The hardiness and capability of the Arab-Muslims as a fighting force during this period was also a factor. The weakness of the empires to the north would have been seen as a clear opportunity for the raiders who had long supported themselves by harrying the frontiers. And there was the timing: Muhammad and his successors were creating and expanding the new Muslim community in the 620s and 630s, as the war between the Byzantines and the Sasanian Persians was entering its last stages and leaving both empires weakened at a critical juncture.

Conquering Persia and the Byzantine Empire

It was not always clear that the Arab-Muslims would be successful against the Byzantines and the Persians, the last empires of antiquity. Nonetheless, starting in 634 and continuing into the early eighth century, they found enormous success conquering much of the territory around the Mediterranean basin and central Asia, going as far west as Spain and Portugal and all the way to the Indus River valley in the east. The new Islamic state, or caliphate (an area under the control of a caliph), was larger than the realm of Alexander the Great, the Romans, or the Han Chinese; it was the largest empire the world had yet seen (diagram).

The Eighth-Century Islamic Caliphate.

A map of southern Europe, northern Africa, and southwestern Asia is shown. The Adriatic Sea, Mediterranean Sea, the Aegean Sea, the Black Sea, the Caspian Sea, the Red Sea, the Gulf of Aden, the Persian Gulf (Arabian Gulf), the Gulf of Oman, and the Arabian Sea are labeled. The northern coastline of Africa, all of the Arabian peninsula, and the land extending north from there to Turkey and then east through Iran and into Afghanistan and Pakistan is highlighted orange and labeled “Islamic Caliphate.” The cities labeled on the map from west to east are: Alexandria, Constantinople, Damascus, Jerusalem, Medina, Mecca, Mosul, Ctesiphon, Aden, and Muscat.
This map shows the extent the new Islamic caliphate had achieved by the end of its first dynasty, the Umayyads. During the eighth century CE, the Umayyads ruled the world’s largest empire. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
The crucial early years of Islamic expansion were overseen by the first four caliphs, a group of rulers who came to be called the “rightly guided” or Rashidun. These four figures—Abu Bakr, Umar, Uthman, and the originally overlooked son-in-law of Muhammad, Ali—ruled between 632 and 661, a period when much Byzantine and Persian territory was conquered, and the message of Islam spread throughout a predominantly Christian Middle East. While the Byzantines and the Persians had employed the Arabian Ghassanids and Lakhmids to guard their borders and serve in their wars, the arrival of the Arab-Muslim armies was unlike anything either empire had seen before.
The Byzantine emperor Heraclius, heralded for bringing victory over the Persians, was not able to enjoy his triumph for very long. Meanwhile, defeated Sasanian Persia was coping with the effects of a destabilizing civil war. The ruler who ultimately emerged in 632, Yazdegerd III, was little more than a puppet king, a child figurehead, and the once-unified Sasanian state devolved into a fractured entity ruled by the noble families.
The Arab-Muslim armies began their invasion with the provinces of Iraq and Syria before moving eastward into the Iranian plateau and westward into Egypt. On all fronts, the first decades of the conflict proved extraordinarily successful for the conquerors. Shortly after winning several skirmishes and capturing the Syrian city of Damascus, the Arab-Muslims bested the Byzantine army at the Battle of Yarmuk in 636. Unable to defend the remaining cities of the region, the Byzantines then abandoned Greater Syria, consisting of what are today Israel, Jordan, Lebanon, Palestine, and Syria. The Arab-Muslim armies continued northward and westward, laying siege to and capturing the Egyptian port city of Alexandria in 641. Many other Byzantine provinces soon followed. In Iraq, the armies of Persia lost to the Arab-Muslims at the Battle of Qadisiyya, bringing an end to any sustained resistance by the Persians.
Still, the conquest of Persia proved to be a longer-term process. Sasanian-controlled territory was vast and geographically diverse, and the independence the Sasanian nobility had wrested from the central government following the war with the Byzantines meant the Arab-Muslims needed to negotiate with many local governors and landed elites for the surrender of their territory. At the same time, dynamics between the Sasanian nobility and the lower classes had already begun changing. The nobility existed in a well-established court culture and practiced the traditional Persian religion of Zoroastrianism. Outside this elite circle, however, Zoroastrianism had long been declining in popularity, while other religious traditions, including Nestorian Christianity and Manichaeism, grew. The collapse of the Sasanian ruling family in Persia also provides a unique glimpse into something that had not happened among the elite before: the brief rise of a female ruler, Boran. The daughter of Khosrow II, Boran came to power briefly during the civil war after the Byzantine victory over her father. While such opportunities for female power in the region were few and far between, her rule underscores that seventh-century Persia was already a state and a people in transition, and the arrival of the Arab-Muslims with the cultural practices of Arabia and the religion of Islam only expedited change.
Although the Byzantines and Persians had put up resistance, by the 650s much of their territory had been taken by the new Islamic state of the Rashidun. Heraclius died in 641, with the territories he and the Byzantines had fought to retake from the Persians largely lost. The Byzantine Empire survived the Arab-Muslim conquests, but it never again controlled much of the territory of the old Roman east. The Sasanian ruler Yazdegerd III fled east to escape capture by the Arab-Muslims or their supporters, spending much of his short life on the run before being killed by his own people in 651. By that time, the entirety of the Persian Empire had effectively been brought into the control of the new Islamic state.

The Conquerors and the Conquered

From the perspective of the Arab-Muslims, the conquest movement had been enormously successful, a demonstration of the power of God and his favoring of their ummah. From the perspective of Christians who were not aligned with the Muslims during this period, the arrival of the Arab-Muslims was also seen as an act of God, a God who was angry at the sinfulness of the Christians and who had sent the Arab-Muslims as a punishment they needed to bear.
Calling these events the “Arab-Muslim conquests” is somewhat misleading, however. While the first years of expansion did see several major battles, including Yarmuk and Qadisiyya, most of the territory came under Islamic control through peace agreements. Cities and regions agreed to terms of surrender that protected their residents, many of their belongings, and their right to practice their religion. Peaceful agreements made sense for non-Muslim populations. Especially during the seventh century, the Muslims maintained a policy of noninterference toward the religious practices of subject populations. As long as they paid taxes to their new Muslim government, the conquered could live in the Islamic state and still practice their religion somewhat freely.
The Muslims developed a legal classification for the Jewish people, Christians, and Zoroastrians who lived under their rule. They referred to them as ahl al-kitab, or People of the Book, which recognized them as monotheists who had received a revealed scripture from God in the past, and who were worthy of protection by the Islamic state so long as they paid taxes and submitted to Muslim rule. For many, this situation was an improvement on their earlier lives. Under Byzantine rule, for instance, those who did not follow the official Christian religion of the empire were often discriminated against. They could be barred from holding certain jobs, charged extra taxes, and otherwise be badly treated as heretics. For Jewish populations, the situation had often been even harsher. Many had been unable to openly practice their faith or gather outside the synagogue. While they were not officially monotheists and were not seen as having a revealed scripture, Zoroastrians under the Muslims were still treated as People of the Book, likely for pragmatic reasons owing to their noble status in Persian society.
The term “Arab-Muslim conquest” has another drawback in that some participants were non-Arabs, including people from East Africa, North Africa, and Persians who chose to join the Muslim armies. Among them were some Amazigh (Berber) tribes from North Africa and the elite Persian cavalry, the asawira. Other fighters were Arabs but had not necessarily formally converted to Islam. These included Arab members of devout Christian tribes such as the Banu Taghlib. There are likely many reasons for non-Arabs and non-Muslims to have contributed to the Muslim effort. Joining in the conquests would at least have entitled the participant to a portion of the spoils of war and standing in the new society, both of which were immensely beneficial.
In the end, the most important differentiator of status in this earliest society was not Arab versus non-Arab or Muslim versus non-Muslim, but rather conqueror versus conquered. Thus, in the first centuries of Islamic history, society was organized into those who paid tax for the protection and benefit of the state, and those who received that payment and provided that protection and those benefits. Those who were ethnically Arab had opportunities to enjoy special preferences within government and society in the earliest decades, but by the end of the eighth century, this distinction eroded as more non-Arabs became involved in the affairs of state.