Bacteria swim by rotating their flagella. They back up or choose new directions at random by changing the direction of the rotation. The probability of such changes is biased by sensory reception. The bias depends on the way in which the intensity ofthe stimulus changes with time, so that the bacteria tend to swim up a gradient of attractant and down a gradient of repellent chemicals.