The two characters combine to create a meaning of “fortunately avoiding a loss.” You are lucky (幸) that you didn't suffer a loss (亏). This captures the essence of relief from a near-miss.
While 幸亏 (xìngkuī) is a universal expression of relief, its frequent use in Chinese can reflect a practical and sometimes fatalistic worldview. It acknowledges that things can easily go wrong and expresses genuine gratitude when they don't. It's less about celebrating a windfall and more about appreciating the avoidance of a problem. A useful Western comparison is the phrase “dodging a bullet.” When you say, “幸亏我出门早,不然就迟到了” (Luckily I left early, otherwise I would've been late), the feeling is similar to “Phew, I really dodged the bullet of being late.” However, 幸亏 is far more common and less dramatic than “dodging a bullet,” integrating this feeling of relief seamlessly into everyday conversation. It's a small, frequent acknowledgment of fortune smiling upon you in minor ways.
幸亏 (xìngkuī) is an incredibly common adverb in spoken Mandarin and informal writing.