The film is about a mathematical genius, Maximillian Cohen (Sean Gullette), who narrates much of the movie. Max, a number theorist, theorizes that everything in nature can be understood through numbers, and that if you graph the numbers properly patterns will emerge. He is working on finding patterns within the stock market, using its billions upon billions of variables as his data set with the assistance of his homemade supercomputer, Euclid.
The film opens with Max narrating a time when he was very young and tried to stare directly at the sun, despite his mother's warnings not to. His eyes were terribly damaged, and his doctors were not sure if they would ever heal. They did, but immediately thereafter he began to be plagued with headaches. The headaches are severe enough to drive him to the brink of madness, and he often passes out from the pain. He also suffers from extreme paranoia, manifested in menacing hallucinations, and some form of social anxiety disorder. Throughout the film, it gets increasingly difficult to separate what is real and what is a product of Max's hallucinations.
In the course of his work, Max begins making stock predictions based on Euclid's calculations. In the middle of printing out the picks, Euclid suddenly crashes, but first spits out a 216-digit number that appears to be nothing more than a random string. Disgusted, Max tosses out the printout of the number. The next morning, Max checks the financial pages and sees that the few picks Euclid made before crashing were accurate. He searches desperately for the printout but cannot find it.
The only social interaction Max seems to have is with Sol Robeson (Mark Margolis), his old mathematics mentor, who had regarded Max as his prize student. Sol had been a leading figure in research into the nature of Pi in his earlier years, but gave it up for reasons that are not yet clear. He sympathizes with Max about the loss of Euclid but becomes unnerved when Max mentions the string of numbers, asking if the string was 216 digits long. When Max questions him about the string, Sol indicates that he came across such a number many years ago. He urges Max to slow down and try taking a break.
At a coffee shop, Max meets Lenny Meyer (Ben Shenkman), a Hasidic Jew who does mathematical research on the Torah. Lenny demonstrates some simple Gematria to Max 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 real mathematical theories, such as the Fibonacci Sequence. Lenny also mentions that he and his fellow researchers are searching for a 216-digit number that is repeated throughout the text of the Torah.
Max is also being pursued by agents of a Wall Street firm, who are interested in his work for financial reasons. One of the agents, Marcy Dawson (Pamela Hart), offers Max a powerful new computer chip in exchange for the results of his work. Max insists that he is uninterested in profit but takes the chip to help his new research into the Torah.
Utilizing the sophisticated chip, Max has Euclid analyze mathematical patterns in the Torah. Euclid crashes again, but once again spits out the 216-digit number. Thereafter, Max appears to become somewhat clairvoyant and able to visualize the stock-market patterns he had been searching for. His headaches also increase in intensity, and he discovers a strange vein-like bulge protruding from his right temple.
During a visit with Sol, his old mentor warns him that the mysterious 216-digit number is more than Max realizes, and seems to have powers of its own. Sol insists that trying to understand it years ago had caused him to suffer a stroke, but Max angrily dismisses Sol's concerns as cowardice.
Marcy Dawson and her henchmen grab Max on the street, threatening him with a gun. They had been using some of Max's formulas to try to make predictions of their own, but their limited understanding of the information has caused them to unwittingly crash the stock market. Lenny and his fellow Hasidim (Henri Falcon) rescue Max, but soon make similar demands on Max to give them the number. They believe the number was meant for them to bring about the Messianic Age. Max refuses, insisting that whatever the source of the number, it has been revealed to him alone.
Driven to the brink of madness, Max experiences another headache and resists the urge to take his pain medication. 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. Max's neighbors discover him unconscious and revive him, breaking his vision. Giving up, Max trepans himself in the right temple, where he believes his mathematical genius is located. Whether this actually occurs is left ambiguous. Later, Max sits on a park bench and reveals that he is no longer able to perform complex mental calculation. He observes the trees blowing in the breeze, at peace.