Formaldehyde is a hazardous volatile organic pollutant commonly found indoors, making selective and accurate detection of formaldehyde crucial. To achieve this, ZnO@ZIF-8 core-shell heterostructures were fabricated using the sacrificial template method, where the 3D ZnO flower-like structures served as the core material. This innovative approach utilizing the ZIF-8 shell as a “selective gas filter” offers a novel pathway for enhancing the selectivity of formaldehyde sensors. Subsequent investigations revealed that the thickness of the ZIF-8 shell significantly influences the material’s performance. Among various configurations tested, the 2-ZnO@ZIF-8 sensor demonstrates the best formaldehyde detection properties, including high response (5 ppm, 5.03), excellent selectivity, short response and recovery times (29/40 s), excellent long-term stability, and a low theoretical detection limit (12.86 ppb) at 175 °C. The enhanced sensing properties can be attributed to the ZIF-8 surface’s high adsorption energy for formaldehyde molecules and the selective screening of gas molecules by ZIF-8. Overall, our study presents a promising strategy for developing highly selective gas sensors for formaldehyde detection, with the potential to contribute to improved indoor air quality monitoring and safety measures.