Bacteria form architecturally complex communities known as biofilms in which cells are held together by an extracellular matrix. Biofilms harbor multiple cell types, and it has been proposed that within biofilms individual cells follow different developmental pathways, resulting in heterogeneous populations. Here we demonstrate cellular differentiation within biofilms of the spore-forming bacterium Bacillus subtilis, and present evidence that formation of the biofilm governs differentiation. We show that motile, matrix-producing, and sporulating cells localize to distinct regions within the biofilm, and that the localization and percentage of each cell type is dynamic throughout development of the community. Importantly, mutants that do not produce extracellular matrix form unstructured biofilms that are deficient in sporulation. We propose that sporulation is a culminating feature of biofilm formation, and that spore formation is coupled to the formation of an architecturally complex community of cells.