A lattice gauge theory is described by a redundantly large vector space that is subject to local constraints and can be regarded as the low-energy limit of an extended lattice model with a local symmetry. We propose a numerical coarse-graining scheme to produce low-energy, effective descriptions of lattice models with a local symmetry such that the local symmetry is exactly preserved during coarse-graining. Our approach results in a variational ansatz for the ground state(s) and low-energy excitations of such models and, by extension, of lattice gauge theories. This ansatz incorporates the local symmetry in its structure and exploits it to obtain a significant reduction of computational costs. We test the approach in the context of a Z 2 lattice gauge theory formulated as the low-energy theory of a specific regime of the toric code with a magnetic field, for lattices with up to 16 × 16 sites (16 2 × 2 = 512 spins) on a torus. We reproduce the well-known ground-state phase diagram of the model, consisting of a deconfined and spin-polarized phases separated by a continuous quantum phase transition, and obtain accurate estimates of energy gaps, ground-state fidelities, Wilson loops, and several other quantities.