Summary The technique of water-alternating-gas (WAG) injection has been widely applied to improve sweep efficiency of gas injections in depleted oil fields. However, injectivity abnormalities have been a limiting factor, adversely affecting the success and the economic feasibility of WAG projects. Heterogeneous distribution of petrophysical properties in carbonate formations is among the parameters causing injectivity loss during WAG cycles. WAG injection reduces the effective fluid mobility in all rock classes, irrespective of their petrophysical properties and flow characteristics. Thus, a larger fraction of fluids flow into the rock classes of higher permeability, resulting in a poor frontal advancement in rock classes of lower permeability. This leads to reduced overall injectivity and loss of WAG operation efficiency. In this paper, we investigate and quantify the effect of spatial heterogeneity in a carbonate formation on injectivity loss during WAG injection. We conduct automatic rock classification on the basis of conventional well logs by use of an unsupervised artificial-neural-network method to characterize the rapid vertical variation of petrophysical properties and mineralogy in a carbonate formation. We then apply a new heterogeneity coefficient to quantify the spatial distribution of rock classes. The introduced heterogeneity coefficient is validated by use of principal-component analysis (PCA) and variogram analysis. The aforementioned technique was applied to 10 wells of the Scurry Area Canyon Reef Operators Committee (SACROC) Unit in west Texas that were subjected to WAG operation. Five of the selected wells in this field exhibited no injectivity abnormality, whereas the other five wells experienced unexpected low gas injectivity during carbon dioxide (CO2) injection and an apparent reduction in water injectivity during the follow-up brine injection. Rock classification generated three rock classes on the basis of mercury-injection capillary pressure (MICP) data and the distribution of porosity, permeability, pore types, and clay content, with Rock Classes 1, 2, and 3 having the best, intermediate, and worse rock quality, respectively. We quantified magnitude of the spatial heterogeneity on the basis of the distribution of rock classes in all 10 wells. We then investigated the effect of heterogeneity on the injectivity loss during WAG injection by comparing the identified heterogeneity coefficients in all wells. The results showed that in the wells with WAG-injectivity loss, the distribution of rock classes is approximately 30% more heterogeneous compared with the wells with no injectivity loss. In the wells with injectivity loss, we also observed approximately 32 and 43% higher occurrence of Rock Classes 1 and 2, respectively, compared with the wells with no injectivity loss. An analysis of the spatial heterogeneity can be applied to improve selection of candidate wells for WAG injection and success of oil recovery.