Bacteria commonly grow in densely populated surface-bound communities, termed biofilms, where they gain benefits including superior access to nutrients and resistance to environmental insults. The secretion of extracellular polymeric substances (EPS), which bind bacterial collectives together, is ubiquitously associated with biofilm formation. It is generally assumed that EPS secretion is a cooperative phenotype that benefits all neighboring cells, but in fact little is known about the competitive and evolutionary dynamics of EPS production. By studying Vibrio cholerae biofilms in microfluidic devices, we show that EPS-producing cells selectively benefit their clonemates and gain a dramatic advantage in competition against an isogenic EPS-deficient strain. However, this advantage carries an ecological cost beyond the energetic requirement for EPS production: EPS-producing cells are impaired for dispersal to new locations. Our study establishes that a fundamental tradeoff between local competition and dispersal exists among bacteria. Furthermore, this tradeoff can be governed by a single phenotype.