Biofilm formation is a process in which microbial cells aggregate to form collectives that are embedded in a self-produced extracellular matrix. Bacillus subtilis is a Gram-positive bacterium that is used to dissect the mechanisms controlling matrix production and the subsequent transition from a motile planktonic cell state to a sessile biofilm state. The collective nature of life in a biofilm allows emergent properties to manifest, and B. subtilis biofilms are linked with novel industrial uses as well as probiotic and biocontrol processes. In this Review, we outline the molecular details of the biofilm matrix and the regulatory pathways and external factors that control its production. We explore the beneficial outcomes associated with biofilms. Finally, we highlight major advances in our understanding of concepts of microbial evolution and community behaviour that have resulted from studies of the innate heterogeneity of biofilms.