The quasi-one-dimensional (1D) metallic conductivity of the perovskite-related SrnNbnO3n+2 compounds is of continuing fundamental physical interest as well as being important for developing advanced electronic devices. The SrnNbnO3n+2 compounds can be derived by introducing additional oxygen into the SrNbO3 perovskite. However, the physical origin for the transition of electrical properties from the three-dimensional (3D) isotropic conductivity in SrNbO3 to the quasi-1D metallic conductivity in SrnNbnO3n+2 requires more in-depth clarification. Here we combine advanced transmission electron microscopy with atomistic first-principles calculations to unambiguously determine the atomic and electronic structures of the SrnNbnO3n+2 compounds and reveal the underlying mechanism for their quasi-1D metallic conductivity. We demonstrate that the local electrical conductivity in the SrnNbnO3n+2 compounds directly depends on the configuration of the NbO6 octahedra in local regions. These findings will shed light on the realization of two-dimensional (2D) electrical conductivity from a bulk material, namely by segmenting a 3D conductor into a stack of 2D conducting thin layers.