The modern description of elementary particles is built on gauge theories. Such theories implement fundamental laws of physics by local symmetry constraints, such as Gauss’s law in the interplay of charged matter and electromagnetic fields. Solving gauge theories by classical computers is an extremely arduous task, which has stimulated a vigorous effort to simulate gauge-theory dynamics in microscopically engineered quantum devices. Previous achievements used mappings onto effective models to integrate out either matter or electric fields, or were limited to very small systems. The essential gauge symmetry has not been observed experimentally. Here, we report the quantum simulation of an extended $U(1)$ lattice gauge theory, and experimentally quantify the gauge invariance in a many-body system of $71$ sites. Matter and gauge fields are realized in defect-free arrays of bosonic atoms in an optical superlattice. We demonstrate full tunability of the model parameters and benchmark the matter-gauge interactions by sweeping across a quantum phase transition. Enabled by high-fidelity manipulation techniques, we measure Gauss’s law by extracting probabilities of locally gauge-invariant states from correlated atom occupations. Our work provides a way to explore gauge symmetry in the interplay of fundamental particles using controllable large-scale quantum simulators.