Type IV pili are bacterial nanomotors that mediate two opposing behaviors on surfaces, spreading and clustering. Here we show that the velocity of motile Neisseria gonorrhoeae depends quantitatively on the fluidity of the phospholipid membrane surface. Using microcontact printing, we confined the surface motility to nonfluid islands within a fluid lipid membrane. On an array of islands, the transition from spreading to clustering was analyzed in real time and at the single cell level, showing that it was triggered by the number of bacteria (7.5 +/- 0.3) for small islands and by the surface density (56 +/- 2%) when the size of the island exceeded 25 microm(2).