Topologically ordered phases of matter display a number of unique characteristics, including ground states that can be interpreted as patterns of closed strings. In this paper, we consider the problem of detecting and distinguishing closed strings in Ising spin configurations sampled from the classical Z2 gauge theory. We address this using the framework of persistent homology, which computes the size and frequency of general loop structures in spin configurations via the formation of geometric complexes. Implemented numerically on finite-size lattices, we show that the first Betti number of the Vietoris-Rips complexes achieves a high density at low temperatures in the Z2 gauge theory. In addition, it displays a clear signal at the finite-temperature deconfinement transition of the three-dimensional theory. We argue that persistent homology should be capable of interpreting prominent loop structures that occur in a variety of systems, making it an useful tool in theoretical and experimental searches for topological order.