I thought I'd write a short and simple intro to how fMRI works. Most such explanations start with the physics of Magnetic Resonance Imaging and eventually explain how it lets you look at brain activity. I'm doing it the other way round, because I like brains more than physics. So - everyone knows that fMRI is a way of measuring neural activation. But what does it mean for a neuron to be active? All brain cells are "active": they're alive, firing electrical action potentials, and sending out neurotransmitters to other cells at synapses. If a certain cell gets more activated, that means that it's firing action potentials faster, or sending out more chemical signals. It's mostly synaptic activity which fMRI picks up.
How do you measure neural activation? You can do it directly by sticking in an electrode to measure action potentials, or use a glass tube to measure neurotransmitter levels. You can put electrodes on the scalp to pick up the electrical fields created by lots of neurons firing. But fMRI relies on an indirect approach: when a brain cell is firing hard, it uses more energy than when it's not. Cells make energy from sugar and oxygen; oxygen is transported in the blood. So when a given cell is working hard, it uses more oxygen, and the oxygen content of nearby blood falls. Synaptic activity, in particular, uses loads of oxygen. So you might expect that highly active parts of the brain would have less oxygen. Counter-intuitively, they actually show an increase in blood oxygen, which is probably a kind of "overcompensation" for the activity (although there may be an "initial dip" in oxygen, it's very brief.) So blood oxygen is a proxy for activation. How do you measure it? Oxygen in blood binds to haemoglobin, a protein that contains iron (which is why blood is red, like rust, and tastes metallic...like iron). By a nice coincidence, haemoglobin with oxygen is red; haemoglobin without oxygen is blueish or purple. This is why your veins, containing deoxygenated blood, are blue and why you turn blue if you're suffocating. You could measure neural activity by literally looking to see how red the brain is. This is actually possible, but obviously it's a bit impractical. Luckily, as well as being blue, deoxygenated haemoglobin acts as a magnet. So blood is magnetic, and the strength of its magnetic field depends on how oxygenated it is. That's really useful, but how do you measure those magnetic fields? Using an extremely strong magnet - like the liquid-helium-cooled superconducting coil at the heart of every MRI scanner, for example - you can make some of the protons in the body align in a special way. If you then fire some radio waves at these aligned protons, they can absorb them ("resonate"). As soon as you stop the radio waves, they'll release them back at you, like an echo - which is why the most common form of fMRI scan is called Echo-Planar Imaging (EPI). All matter contains protons; in the human body, most of them are found in water. Each proton only responds to a specific frequency of radio waves. This frequency is determined by the strength of the magnetic field in which it sits - stronger fields, higher frequencies. Crucially, the magnetic fields surrounding deoxygenated blood therefore shift the radio frequency at which nearby protons respond. Suppose a certain bit of the brain resonates at frequency X. If some deoxygenated blood appears nearby, it will stop them from responding to that frequency - by making them respond to a different one. fMRI is essentially a way of measuring the degree to which protons in each part of the brain don't respond at the "expected" resonant frequency X, due to interference from nearby deoxygenated haemoglobin. But how do you know what resonant frequency to expect? This is the clever bit: simply by varying the magnetic field across different parts of the brain. Say you make the magnetic field at the left side of the head slightly stronger than the one at the right - a magnetic gradient. The resonant frequency will therefore vary across the head: the further left, the higher the frequency. This is what the "gradient coils" in an MRI machine do.
Gradient coils therefore translate spatial location into magnetic field strength. And as we know, magnetic field strength = resonant frequency. So spatial location = magnetic field strength = resonant frequency. All you then need to do is to hit the brain with a burst of radio waves of all different frequencies - a kind of white noise called the "RF Pulse" - and record the waves you get back. The strength of the radio waves at a given frequency therefore corresponds to the amount of protons in the appropriate place - so you can work out the density of matter in the brain based on the frequencies you get. Also, different kinds of tissues in the body respond differently to excitation; bone responds differently to brain grey matter, for example. So you can build up an image of brain structure by using magnetic gradients.
Of course you can't scan the whole brain at once: you scan it in slices, divided up into roughly cubic units called voxels. Typically in fMRI these are 3x3x3 mm or so, but they can be much smaller for specialized applications. The smaller the voxels, the longer the scan takes because it requires more gradient shifting. The loud noises that occur during MRI scans are caused by the gradient coils changing the gradients extremely quickly in order to scan the whole brain. Modern scanners typically image the whole brain once every 3 seconds, but you can go even faster. As we've seen, deoxygenated blood degrades the image nearby, in what's called the Blood Oxygenation Level Dependent (BOLD) response. Neural activation increases oxygen and literally makes the brain light up; you could, in theory, see the changes with the naked eye. In fact, they're tiny, and there is always a lot of background noise as well, so you need statistical analysis to determine which parts light up, and then map this onto the brain as colored blobs. But that's another story...