Navier–Stokes explained for programmers

Navier–Stokes explained for programmers
$1,000,000prize from the Clay Institute, offered in 2000
1822Navier writes the equation; Stokes completes it in 1845
4pieces: advection, pressure, viscosity and forces
2blowup claims in 2026, not yet reviewed
The Navier–Stokes equation explained for programmers (the million dollar problem)
I also explain it in this video, on my channel Articulator EN. The figures in this post are frames from the video, and the fluids you see are really simulated with Jos Stam's method.

What a fluid islink

A fluid is anything that flows: water, air, honey, smoke. To describe one, imagine filling space with tiny arrows. At every point, the arrow tells you where the fluid is going and how fast. That's a velocity field.

If you're a programmer, think of it as a huge array: every cell stores a velocity (two numbers in the plane, three in space) and a pressure. The whole state of the fluid at one instant is that array. Nothing else.

A grid of cells over a simulated fluid, each cell with the arrow of its velocity
The fluid as an array: one velocity arrow per cell.

And if the state is an array, time is a loop. At every step you compute how each cell changes and start again, just like a game's main loop. That's how fluid simulations work. In 1999, Jos Stam published Stable Fluids, a method so robust that it brought smoke and water to countless video games and effects tools. The question is which rules each cell follows on every pass of the loop. Those rules are the Navier–Stokes equation.

The equation, piece by piecelink

The core idea comes from Newton: force equals mass times acceleration. Push something and it speeds up. Navier–Stokes is that law applied to every little piece of fluid. On one side goes how the velocity of that piece changes; on the other, everything that pushes it. Claude-Louis Navier wrote it in 1822 and George Stokes completed it in 1845. For a fluid that doesn't compress, like water, it reads:

The equation

∂u/∂t + (u·∇)u = −∇p + ν∆u + f   ·   ∇·u = 0

The Navier–Stokes equation with each term in its own color: change, advection, pressure, viscosity and forces
Each color is one piece of the equation.

It looks like hieroglyphics, but it's four ideas:

  • Advection, (u·∇)u: the fluid carries itself. Think of a leaf falling into a river: the current drags it away. Velocity also travels with the current, as if it were that leaf. The strange part is that here velocity drags itself: it's a feedback loop, the output goes back in as input. This is the nonlinear term, and it's to blame for almost everything hard in this post.
  • Pressure, −∇p: what goes in comes out. Water can barely be compressed: push on one side and it has to come out somewhere else, like a packed subway car. The rule ∇·u = 0 says that in every cell what goes in equals what comes out, and pressure is the mechanism that enforces it: it pushes from where there's too much toward where there's room. In simulation code, this step is called projection.
  • Viscosity, ν∆u: a blur filter. It's internal friction, what makes honey thick and water runny. And here comes something familiar: the Laplacian ∆u makes each cell look more like the average of its neighbors. That's exactly a blur, like the one in your photo editor. With a lot of viscosity, two colliding jets stall like honey; with very little, they curl into swirls.
  • Forces, f: whatever comes from outside. Gravity, a fan, a stirring spoon.
Two colliding jets: with high viscosity they stall, with low viscosity they form swirls
The same simulation with high and low viscosity.

A handful of symbols that describe the atmosphere, the oceans and the air around an airplane. It looks harmless. It isn't.

The million dollar questionlink

In 2000, the Clay Mathematics Institute picked seven open problems and offered a million dollars for each: the Millennium Problems. So far only one has been solved, the Poincaré conjecture, and its author, Grigori Perelman, turned the prize down. Another of the seven is understanding Navier–Stokes.

Careful: nobody is asking you to solve the equation with an exact formula, which we can only do in very simple cases. The question is much more basic:

The question

If a fluid in three dimensions starts out smooth and with finite energy, does it stay smooth forever? Or can the velocity, in a finite time, shoot off to infinity at some point?

Smooth means no jumps and no spikes: however far you zoom in, the velocity changes little by little, like a smooth curve. The opposite is a blowup or singularity: a point where, as you zoom in, the velocity grows without limit and the equation stops making sense. For a programmer, it's as if your simulation returned a NaN, not because of a bug, but because the physics itself demands it.

Maximum speed against time: one bounded curve and another that shoots to infinity before a time T
Smooth forever, or blowup at a finite time T.

There are two ways to win the prize, and both will sound familiar:

Prove it never blows up

For any smooth starting fluid. It's like proving a program never crashes, for every possible input.

Find one case that blows up

A single concrete example. It's like finding the input that crashes it. But seeing it in a simulation doesn't count: you have to prove it.

For more than twenty years, nobody managed either one.

Why it's so hardlink

There's a fight inside the equation. Advection concentrates energy, piling it into smaller and more intense regions. Viscosity blurs: it spreads things out and smooths them. If viscosity always wins, the fluid stays smooth; if at some point concentration outruns the blurring, it blows up. Knowing who wins at very small scales is the whole problem.

Concentration has a well-known mechanism: vortex stretching. Think of a figure skater spinning with her arms out: when she pulls them in, she spins much faster. A vortex in three dimensions does the same: if the flow stretches it, it gets thinner and spins faster, and spinning faster, it stretches even more. It's a loop that feeds itself.

In two dimensions that loop doesn't exist, because a flat vortex can't be stretched. That's why the problem has been solved in the plane for decades: the fluid always stays smooth. In three dimensions, energy, the only thing we know how to control well, isn't enough: a finite amount of energy could, in principle, squeeze into an ever tinier point and spin without limit.

So why don't we just simulate it? Because a computer works with cells of a fixed size, like the pixels on a screen, and a blowup would happen at an infinitely small point. However many cells you use, there's always something smaller you can't see. If the simulation gives huge values, you can't tell whether it's the physics or the numerical error. Simulations give hints, but they don't prove anything.

Turbulencelink

Open a tap slowly: at first the stream is smooth and clear; open it more and it turns chaotic. What decides the switch is the Reynolds number: speed times size, divided by viscosity. When it's small, the flow is orderly (laminar); when it's large, turbulent. Behind an obstacle, swirls break off one after another, first on one side and then on the other.

Flow past a cylinder shedding alternating swirls
Swirls breaking off behind an obstacle.

In turbulence, energy walks down a staircase: big swirls break into smaller ones, and those into even smaller ones, until viscosity stops them and the energy ends up as heat. Lewis Richardson summed it up in 1922 with a poem: big whirls have little whirls that feed on their velocity, and little whirls have lesser whirls, and so on to viscosity. In 1941, Kolmogorov worked out how energy is shared along that staircase. Leonardo da Vinci was already drawing these swirls five hundred years ago, and Richard Feynman described turbulence as a very old problem, common to many fields and still unsolved.

The link to the prize: a blowup would be the extreme case of that cascade, all the energy rushing down the staircase into a single point in a finite time.

What we already knewlink

  • Leray, 1934: weak solutions always exist, for all time. A weak solution is like a blurry photo: you know it's there and its energy is under control, but you can't guarantee the details. It could hide points where the velocity shoots up. Leray already suspected those blowups had to do with turbulence.
  • Caffarelli, Kohn and Nirenberg, 1982: if there's a blowup, it happens in very few places. The bad points form a tiny set, thinner than any curve in space and time.
  • Short times and small data: if you start with a smooth fluid, the solution exists and stays smooth at least for a while; and if the fluid starts out calm enough, it stays smooth forever. Like a program that passes every test with small inputs.
  • Terence Tao, 2016: he changed the equation slightly, keeping the energy exactly as in the original, and inside that modified fluid he built a kind of computer made of fluid: a machine that passes its energy to a smaller, faster copy of itself, again and again, until it blows up in a finite time. The lesson: any proof that Navier–Stokes never blows up has to use something more than energy.
  • Euler, with no viscosity: in 2014, Thomas Hou and Guo Luo saw a candidate blowup in simulations of a fluid spinning inside a cylinder, and in 2022 Jiajie Chen and Thomas Hou proved it with computer assistance: rigorous calculations where every number comes with a guaranteed error bound.
Tao's fluid machine: ever smaller and faster copies passing the energy along
Tao's idea: a fluid programmed to hand its energy to a smaller copy.

Fall 2026link

Which brings us to this year, with two announcements less than three months apart:

OpenAI · September 8

An internal model, with about ten thousand agents working at once, found according to its announcement a blowup: a fluid that starts smooth and at rest and develops a singularity in a finite time. But with an outside force, smooth and carefully chosen. The proof was also checked in Lean. OpenAI said it won't claim the prize.

Alpöge and Buckmaster · November 20

Their paper goes after the case that matters: no force. They claim to have found smooth data with finite energy, in all of space and in a periodic box, whose solutions blow up in a finite time, copying themselves at smaller and smaller scales.

Does OpenAI's result count? The wording of the official problem (Fefferman's) allows a force, so it might. But many mathematicians see it as an easier problem: if you can push the fluid however you like, it's less surprising that it blows up. The interesting case was always the fluid left alone.

Alpöge and Buckmaster's work is curious in how it was done: they first wrote the proof in Lean, a language where the computer verifies every step (think of a compiler for proofs), and then turned it into text for humans with the help of AI agents. One part depends on a certificate: an approximate solution that satisfies certain inequalities, checked by computer with interval arithmetic. That certificate hasn't been released yet, and that check sits outside Lean.

So, is it solved? We can't say yet. The Clay Institute still lists the problem as active. In 2014, Mukhtarbay Otelbayev announced the opposite proof (that it never blows up), and within a few weeks a mistake was found. Lean checking the code doesn't guarantee that the formal statement is exactly the problem, and the certificate still has to be checked. If it holds up, the answer to the million dollar question would be: yes, the equation can break.

Why should you care?link

For tomorrow's weather or the design of an airplane, not much: engineers have used these equations for decades in simulations that work very well. A blowup would happen at tiny scales, where water is no longer a continuum but molecules. But it does change what we know: the model we use for almost everything can break. And it changes how math gets done: AI agents and verifiers like Lean have just stepped into the hardest problem in fluids.

Try it yourselflink

Jos Stam's method fits in a few lines of Python with NumPy. This version uses a periodic grid and the FFT for viscosity and projection; each line of the loop is one piece of the equation. You move the velocity with advection, blur it with viscosity, add the forces and, at the end, project so that what goes in comes out:

import numpy as np
from scipy.ndimage import map_coordinates

N, dt, nu = 128, 0.1, 0.0005           # periodic N×N grid, time step, viscosity
k = np.fft.fftfreq(N) * 2 * np.pi
KX, KY = np.meshgrid(k, k)
K2 = KX**2 + KY**2; K2[0, 0] = 1
y, x = np.mgrid[0:N, 0:N].astype(float)
u = np.zeros((N, N)); v = np.zeros((N, N)); ink = np.zeros((N, N))

def advect(q, u, v):                   # where does whatever lands in each cell come from?
    return map_coordinates(q, [y - v * dt, x - u * dt], order=1, mode="grid-wrap")

for step in range(200):
    jet = np.exp(-((x - 20)**2 + (y - N / 2)**2) / 20)
    u += 30 * jet * dt; ink += jet                            # 4. forces
    u, v, ink = advect(u, u, v), advect(v, u, v), advect(ink, u, v)   # 1. advection
    uh, vh = np.fft.fft2(u), np.fft.fft2(v)
    uh *= np.exp(-nu * K2 * dt * N**2); vh *= np.exp(-nu * K2 * dt * N**2)   # 3. viscosity = blur
    div = KX * uh + KY * vh                                   # 2. pressure: projection
    uh -= KX * div / K2; vh -= KY * div / K2                  #    (what goes in comes out)
    u, v = np.fft.ifft2(uh).real, np.fft.ifft2(vh).real

# import matplotlib.pyplot as plt; plt.imshow(ink); plt.show()

Plot the ink with imshow and you'll see a jet curling up. Try raising nu and watch the blur win as the jet turns into honey. To go further, look up "Stable Fluids" by Jos Stam (SIGGRAPH 1999).

In shortlink

The Navier–Stokes equation is Newton's law for every little piece of fluid: advection, pressure, viscosity and forces. The Millennium Problem asks whether a smooth fluid can blow up in a finite time. This fall, two papers say yes, one with a force and one without, and the community is still checking them.

In one sentence

Two hundred years later, the answer may be that the (mathematical) water can blow up… if the proof survives review.

Do you think the proof will hold up?

Sourceslink

Continue reading

Last posts -->

Have you seen these projects?

Gymnasia

Gymnasia Gymnasia
Expo
React Native
TypeScript
OpenAI
Anthropic

Fitness app with two agents that run entirely on the device, with no backend, so the user's data never leaves the phone. A BYOK conversational coach with local tools and a remote system prompt with offline fallback, plus a food estimator that pulls macronutrients out of a photo of the plate, with barcode scanning against OpenFoodFacts.

LangGraph Deep Researcher

LangGraph Deep Researcher LangGraph Deep Researcher
Python
LangGraph
FastAPI
React
TypeScript
Docker

Multi-agent research system built with LangGraph. A supervisor breaks your question down into topics and launches search sub-agents in parallel; each one compresses its findings before handing them to a writer agent that produces the final sourced markdown report. Live streaming over WebSockets, a configurable model per role and bring-your-own API keys that are never persisted server-side.

Tau

Tau Tau
Python
LangChain

Multi-agent tutoring system for secondary school students, with one agent per subject and course material written and validated by a team of teachers. It was used with real students at a private school in Spain and at a secondary school in Colombia.

View all projects -->
>_ Available for projects

Do you have an AI project?

Let's talk.

maximofn@gmail.com

Machine Learning and AI specialist. I develop solutions with generative AI, intelligent agents and custom models.

Do you want to watch any talk?

Last talks -->

Do you want to improve with these tips?

Last tips -->

Use this locally

Hugging Face spaces allow us to run models with very simple demos, but what if the demo breaks? Or if the user deletes it? That's why I've created docker containers with some interesting spaces, to be able to use them locally, whatever happens. In fact, if you click on any project view button, it may take you to a space that doesn't work.

Flow edit

Flow edit Flow edit

FLUX.1-RealismLora

FLUX.1-RealismLora FLUX.1-RealismLora
View all containers -->
>_ Available for projects

Do you have an AI project?

Let's talk.

maximofn@gmail.com

Machine Learning and AI specialist. I develop solutions with generative AI, intelligent agents and custom models.

Do you want to train your model with these datasets?

short-jokes-dataset

HuggingFace

Dataset with jokes in English

Use: Fine-tuning text generation models for humor

231K rows 2 columns 45 MB
View on HuggingFace →

opus100

HuggingFace

Dataset with translations from English to Spanish

Use: Training English-Spanish translation models

1M rows 2 columns 210 MB
View on HuggingFace →

netflix_titles

HuggingFace

Dataset with Netflix movies and series

Use: Netflix catalog analysis and recommendation systems

8.8K rows 12 columns 3.5 MB
View on HuggingFace →
View more datasets -->