Foamed concrete is an essential material in engineering that can be categorized into two types based on density distribution, namely uniform foamed concrete (UFC) and gradient foamed concrete (GFC). However, there exists a research gap concerning the mesoscopic deformation mechanism of UFC and GFC. The objective of this research is to bridge this gap by examining the quasi-static compression characteristics of UFCs with three distinct densities and GFCs with different density sequences. The results reveal that the strength of pore walls significantly influences the failure mechanism of UFCs with varying densities. Specifically, UFCs with low density exhibit weak pore-wall strength, leading to stress concentration at the pore-wall junction. During compression, these weak pore walls are widely dispersed within the specimen, resulting in a powdering failure mode. Conversely, UFCs with high density possess stronger pore walls, which prevent the powdering failure mode by maintaining adequate pore-wall strength. Nevertheless, the existence of a dominant crack within the specimen results in a splitting failure mode. In the context of GFCs, deformation occurs in a sequence from low to high density, with each layer exhibiting a failure mode corresponding to its density. Note that the last-deforming layer in this brittle gradient foam cannot attain the strength of the corresponding uniform foam. This is due to the failure of the second layer, which results in uneven contact surfaces and prompts the third layer to crack simultaneously. Finally, a statistical model is developed to forecast the compressive Stress–strain curve of foamed concrete, demonstrating remarkable agreement with experimental data.