AbstractThe mechanical behavior and failure mode of porous rocks vary with their microstructures. The formation of compaction bands (CBs) has been captured with high precision via in situ synchrotron CT and kinematic characteristics can be attained by image analysis. However, the stress characteristics cannot be directly evaluated from images, and how porosity heterogeneity triggers local instability and leads to the formation of CBs is not yet fully understood. To address this problem, we established a finite element (FE) model of the solid skeleton of a Leitha limestone sample based on X‐ray μCT data, considering the heterogeneity of pores and plastic hardening, and reproduced the evolution of strain localization and CBs. Our results revealed that the heterogeneity of porosity has a profound influence on the formation and propagation of CBs. Precursory stresses always appear very early around the pores where compaction bands develop, and the stress state of most points in CBs is quasi‐uniaxial compression, which has significantly high maximum principal stress σ1 in a direction subparallel to the sample axis, causing yield then compaction failure. Also, using a simplified FE mesh and ignoring the fracture of particles underestimate the extreme stress and porosity reduction—these can be improved by using fine mesh and involving grain‐scale fracture mechanics. Our study proves the feasibility and reliability of the CT‐FE simulation scheme, which can be extended to investigating the stress distribution and evolution of different rock types with a spectrum of failure modes if in situ CT data of rock deformation is available.