Maximilian Cohen, the main character, narrates the movie. Max is a mathematician, who develops a theory about the key to the world: a number that can predict patterns in nature. He begins to test this theory by researching patterns in the US stock market and the numbers it provides. To aid in his search, Max built a supercomputer named Euclid. Max performs his research in his apartment in Chinatown in New York City. He often experiences headaches throughout the movie that often cause him to pass out, stemming from a young age when he would stare directly at the sun. Max also experiences hallucinations, anxiety, and paranoia, which cause him to be an unreliable narrator at some points. Because of this, Max can perform large mathematical calculations in his head. This eventually impresses a woman who lives near him, Jenna.
During his research, Max uses Euclid to make stock predictions. When Euclid begins printing out these predictions, it suddenly crashes, while printing a 216-digit random number. Max throws away this piece of paper, thinking this is an error. The next day, Max discovers that these predictions Euclid made were accurate, and checks them with the stock numbers. He digs through the trash but cannot find the paper that Euclid printed.
Max meets with a man named Sol Robeson, his old math teacher, who is now ill. At the beginning of his life, Sol had undertaken experimentation with the number Pi, or 3.14159. Max speaks with him about Euclid's crashing and the string of numbers he printed. Sol reacts shockingly, saying that he also came across this number, and advises Max to take a break from his research. Later Max meets with Lenny Meyer, a Jew who researches the Torah and its numerical patterns. Lenny shows that the Torah contains a group of numbers that many believe is a code from God. He discusses that he and other researchers are looking for a 216-digit sequence in the Torah.
During this time, Max is being hunted down by representatives of a Wall Street firm, who seek to exploit his mathematical work. Marcy Dawson, one of these agents, offers to give Max a computer chip in return for his numerical work on the stock market. Max refuses but takes the chip anyway to fuel his investigation into the Torah. He then employs Euclid to use to chip to study the numbers in the Torah. Euclid prints out the 216-digit number but crashes. Then, Max seems to be hallucinating, but starts to envision patterns in the stock market numbers, what he has been searching for since the beginning. Max notices that the pain in his head seems more intense than usual. Later, he goes back to see Sol, who warns him about the dangers of the 216-digit code.
Later one night, Marcy Dawson and agents from her firm kidnap Max to get him to describe the 216-digit number and its meaning to control the stock market. Lenny eventually saves him from the agents but also wants to take advantage of Max and his knowledge. Lenny then takes Max to a Jewish synagogue, where he reveals that the 216-digit number represents the “unspeakable name of God”. Max declines to help them and claims that he is the only one who understands the number and meaning.
Max eventually escapes and goes to see Sol, when he discovers from Sol’s daughter that he has passed away. He then looks through Sol’s apartment and discovers a piece of paper with the number. Max brings the paper back to his apartment, where he eventually passes out due to an excruciatingly painful headache. While he is unconscious, Max envisions himself in a vacant white area where all 216 digits are repeated continuously. When Max awakens, he discovers that the number is the cause of his headaches. He destroys the piece of paper and spontaneously drills a hole in his head to rid the number from his brain.
At the end of the movie, Max and a neighborhood girl are in the park, where she is seen giving him math problems. She asks him if he knows what 748 divided by 238 is, the estimate of Pi. Max is unable to solve any of the problems, living a calm life, newly freed from the distress caused by the number.