The study theoretically substantiates the relationship between the redshift in the electromagnetic spectrum of space objects and their gravity and demonstrates it with computational experiments. Redshift, in this case, is a consequence of a decrease in the speed of the photons emitted from the surface of objects, which is caused by the gravity of these objects. The decline in the speed of photons due to the gravity of space gravitating object (GO) is defined as ΔC = C-C ', where: C' is the photon speed changed by the time the receiver records it. Then, at a change in the photon speed between a stationary source and a receiver, the redshift factor is determined as Z = (C-C ')/C'. Computational experiments determined the gravitational redshift of the Earth, the Sun, a neutron star, and a quasar. Graph of the relationship between the redshift and the ratio of sizes to the mass of any space GOs was obtained. The findings indicate that the distance to space objects does not depend on the redshift of these objects.