Mathematician Joseph Mazur was in the back of a van snaking through the mountains of Sardinia when he heard one of his favorite coincidence stories. The driver, an Italian language teacher named Francesco, told of meeting a woman named Manuela who had come to study at his school. Francesco and Manuela met for the first time in a hotel lobby, and then went to have coffee.

They spoke for an hour, getting acquainted, before the uncomfortable truth came out. Noting Manuela’s nearly perfect Italian, Francesco finally asked why she decided to come to his school.

“She said, ‘Italian? What are you talk about? I’m not here to learn Italian,’” Mazur relates. “And then it dawned on both of them that she was the wrong Manuela and he was the wrong Francesco.” They returned to the hotel lobby where they had met to find a different Francesco offering a different Manuela a job she didn’t want or expect.

The tale is one of the many stories that populate Mazur’s new book, “Fluke,” in which he explores the probability of coincidences.

Mazur argues that most of the coincidences we experience -- like stumbling into a close friend halfway around the world, meeting someone with the same birthday, or even dreaming of an event before it happens -- can be explained by simple mathematics. If coincidences seem so surprising to us, it's because people often fail to understand how the basic laws of probability work.

**The chance of meeting someone with your birthday**

For example, you might be surprised to meet someone who shares your birthday. But should you be?

Mathematicians call this "the birthday problem," and they usually phrase it like this: How big of a group of people do you have to assemble before there’s a 50-50 chance that two of the people share the same birthday? If you haven’t heard this problem before, take a guess now before reading further.

Right away, you know that if you assemble a group of 366 people, there's 100 percent probability that two people will have the same birthday -- since there are only 365 days in a year, excluding leap year. But the probability is still almost certain with a much smaller group than that.

For this problem, it's easier to look at the opposite case, the probability that no two people in a room have the same birthday. To figure out the probability of two independent events occurring together, like two people being born on the same day, you need to multiply the probabilities of each event. So the probability that two people do not share the same birthday is 365/365 x 364/365.

That equals about 99.7 percent -- meaning that, with just two people, it's very likely neither will have the same birthday. The probability that three random people do not share the same birthday is 99.18 percent.

* [When to stop dating and settle down, according to math] *

But as you add people to this equation, the probability that no two people are born on the same day starts to fall, first gradually, and then sharply. With five people, it's 97.3 percent. At 15 people, it's 74.7 percent. And to get better than even odds (50 percent or more) that two people in the room have the same birthday, you only have to assemble 23 people.

It might seem strange that that number is so low, but consider this -- every person you add to the mix is compared independently with every other person in the group. Among 23 people, there are 253 potential pairings -- which creates a lot of potential for two people to share a birthday.

As the graph below shows, by the time you reach 60 people, it's close to certain that the group will contain a birthday match.

The problem has interesting practical applications -- for example, figuring out how likely it is that the FBI's database of genetic material contains random matches between people. While the kind of DNA readings that are used to convict suspects in criminal cases are highly unique, studies have shown that the chance of a random match between two unrelated people may be higher than convicting juries assume.

**The chance of a monkey writing Shakespeare**

Mazur discusses another problem that tells you a lot about how people misunderstand probabilities: the monkey problem, which originated with mathematician Emile Borel.

In 1913, Borel decided to tackle an age-old question about randomness, Mazur says. “He asked the question, ‘Could totally random events amount to something meaningful?’ And the popular rendition of the question soon became, ‘Could a monkey randomly hitting the keys of a keyboard type out a Shakespearean sonnet?’”

You’ve probably heard the question before – it’s become widespread in pop culture, including in this Simpson’s clip from 1993, in which Mr. Burns keeps a roomful of monkeys hammering away on typewriters, in hope of creating the next great work of literature:

Borel's answer to the monkey problems was, essentially, yes -- a monkey will eventually type out a Shakespearean sonnet, though it could take a very long time. As Mazur says, the probability of a monkey randomly typing "shall" -- as in "Shall I compare thee to a summer's day" -- is in itself nearly 1 in 12 million.

But if the monkey tries many, many times, or more fellow monkeys join it in its endeavor, that probability starts to drop. With 8.2 million tries, the monkey has a better than even chance of typing the word "shall."

This same principle is used in brute force attempts to crack passwords, in which algorithms use trial and error methods to quickly run through potential password combinations. This is why longer passwords are so much more secure than shorter ones, just as it's much harder for the monkey to type out a sonnet than the word "shall."

**Why coincidences are so surprising**

A central argument of Mazur’s book is that people tend to make several common mistakes when thinking about probabilities.

For example, think of probability estimate like FiveThirtyEight's 2016 Election Forecast, which in early November showed Democratic candidate Hillary Clinton with a 70 percent chance of winning and Republican candidate Donald Trump with a 30 percent chance. Many people look at a lopsided probability like that and assume that a Clinton win is all but assured. And if Donald Trump were to be victorious, some might assume FiveThirtyEight got it wrong.

But that's not, of course, how probability works. With more than a one-in-four chance, Donald Trump could still easily win the 2016 election.

* [There’s a mathematical reason you’re less popular than your friends] *

Another reason people tend to misunderstand probability is our selective attention -- we notice and remember coincidences, but we hardly ever heed their absence. Think of all the people you've met who don't share your birthday, for example. It's a huge number in comparison to those who do share it. After meeting so many people who don't share your birthday, you're bound to meet someone who does.

This is a point that's illustrated by the monkey problem -- as the number of trials rises, even very rare events have a high likelihood of occurring.

Something similar happens with the Francesco and Manuela story. It seems like a strange event, but as you add in other pairs of popular names, and other hotel lobbies around the world, the probability of an incident of this type occurring begins to grow.

“The mistaken identity event is more common than we think because numbers behind them are larger than we imagine," Mazur writes. "[I]f we include all the hotel lobbies of the entire world, our number would grow so large that we should be certain that two pairs of people will have a mistaken identity meeting in some hotel lobby (I would guess) somewhere every hour!”

This tendency to overestimate or underestimate particular numbers is what gives rise to our great surprise at many coincidences. As Mazur writes, “we are often deceived by the magnitude of our world.” With so many chance events occurring to so many people around the world, stunning coincidences are only natural.

*You might also like: *

The mathematically proven winning strategy for 14 of the most popular games

How to predict the future better than anyone else

Three basic mistakes people make at casinos, according to a math expert