Many bacteria in nature exist in multicellular communities termed biofilms. Cells within biofilms are embedded in a primarily self-secreted extracellular polymeric matrix that provides rigidity to the biofilm and protects cells from chemical and mechanical stresses. In the Gram-positive model biofilm-forming bacterium Bacillus subtilis , TasA is the major protein component of the biofilm matrix, where it has been reported to form functional amyloid fibres contributing to biofilm structure and stability. The structure of TasA fibres, however, and how fibres scaffold the biofilm at the molecular level, is not known. Here, we present electron cryomicroscopy structures of TasA fibres, which show that rather than forming amyloid fibrils, TasA monomers assemble into filaments through donor strand complementation, with each subunit donating a β-strand to complete the fold of the next subunit along the filament. Combining electron cryotomography, atomic force microscopy, and mutational studies, we show how TasA filaments congregate in three dimensions to form abundant fibre bundles that are essential for B. subtilis biofilm formation. This study explains the previously observed biochemical properties of TasA and shows, for the first time, how a bacterial extracellular globular protein can assemble from monomers into β-sheet-rich fibres, and how such fibres assemble into bundles in biofilms. We establish a hierarchical, atomic-level assembly mechanism of biofilm scaffolding that provides a structural framework for understanding bacterial biofilm formation.