Max Cohen is the story's protagonist and unreliable narrator. Unemployed, and living in a dreary Chinatown apartment in New York City, Max is a number theorist who believes that everything in nature can be understood through numbers. He is capable of doing simple arithmetic calculations involving large numbers in his head, a skill that impresses Jenna, a small Chinese-American girl with a calculator who lives in his apartment building. Max also suffers from cluster headaches, as well as extreme paranoia, hallucinations, and social anxiety disorder. Other than Devi, a young woman living next door who sometimes speaks to him, Max's only social interaction is with Sol Robeson, his old mathematics mentor who is now an invalid.
Max begins making stock predictions based on the calculations of his computer, Euclid. In the middle of printing out its picks, Euclid suddenly crashes after spitting out a seemingly random 216-digit number, as well as a single pick at one-tenth its current value. Disgusted, Max tosses out the printout of the number. The next morning, he checks the financial pages and sees that the pick Euclid made was accurate. He searches desperately for the printout but cannot find it. Sol becomes unnerved when Max mentions the number, asking if it contained 216 digits. When Max questions him about the number, Sol indicates that he came across it many years ago. He urges Max to slow down and try taking a break.
At a coffee shop that he frequents on a daily basis, Max meets Lenny Meyer, a Hasidic Jew who coincidentally does mathematical research on the Torah. Lenny demonstrates some simple Gematria, the correspondence of the Hebrew alphabet to numbers, and explains how some people believe that the Torah is a string of numbers that form a code sent by God. Max takes an interest when he realizes that some of the number concepts Lenny discusses are similar to other mathematical concepts, such as the Fibonacci sequence. Max is also met by agents of a Wall Street firm who are interested in his work. One of the agents, Marcy Dawson, offers Max a classified computer chip called "Ming Mecca" in exchange for the results of his work, which Max eventually accepts.
Using the chip, Max has Euclid analyze mathematical patterns in the Torah. Euclid spits out the 216-digit number before crashing again. When his computer refuses to print out the number, Max begins to write it down. Midway through the writing, Max realizes that he knows the pattern, undergoes a sudden epiphany, and passes out. Thereafter, Max appears to become clairvoyant and is able to visualize the stock market patterns he had been searching for. But his headaches also increase in intensity, and he discovers a strange vein-like bulge protruding from his right temple. Max has a falling out with Sol after the latter urges him to quit his work.
One evening, Dawson and her agents grab Max on the street and try to force him to explain the number. They had found the original printout that Max threw away and had been trying to use it to manipulate the stock market in their favor, but as a result, caused it to crash. Although Max is held at gunpoint, Lenny drives by and rescues him. However, Lenny and his companions make similar demands on Max to give them the number. They take him to a nearby synagogue where they finally reveal their intentions: they believe the 216-number was meant for them to bring about the messianic age, as the number represents the unspeakable name of God. Max refuses, insisting that whatever the source of the number is, it has been revealed to him alone.
Max flees and tries to visit Sol, only to find out from his daughter, Jenny, that he has just died from another stroke. Max searches Sol's apartment and finds mathematical scribblings similar to his own, eventually finding a piece of paper with the number. Back in his own apartment, Max is driven to the brink of madness when he experiences another headache and resists the urge to take his painkillers, which causes him to destroy some of the parts of Euclid. Believing that the number and the headaches are linked, Max tries to concentrate on the number through the pain. After passing out, Max has a vision of himself standing in a white void and repeating the digits of the number. The vision ends with Max hugging Devi, who turns out to be a hallucination. Max stands alone in his trashed apartment. Max burns the paper with the number and blithely performs an impromptu trepanning on himself in the right cerebral hemisphere with a power drill.
Later, in the final scene, Jenna approaches Max in a park asking math problems, including 748 ÷ 238, which is an approximation for Pi. Max smiles and claims that he doesn't know the answer to them. No longer able to solve complex mathematics or experience headaches or paranoid thoughts, Max sits on the park bench and observes the trees blowing in the breeze, at peace.