The bacterial cell wall lies just outside the plasma membrane and provides shape and protection to the cell. It is composed of peptidoglycan, which gives rigidity through a mesh-like structure. Gram-positive bacteria have a thick peptidoglycan layer that is the cell wall, while gram-negative bacteria have a thin peptidoglycan layer surrounded by an outer membrane with lipopolysaccharides that act as endotoxins. Structures like capsules, S-layers, and fimbriae allow bacteria to attach to surfaces and provide additional protection.