The characters literally combine to mean “The sun (日) is approaching (薄) the western (西) mountains (山).” This creates a beautiful and somber image of a sunset, which serves as the direct metaphor for the idiom's meaning of being near the end.
The origin of 日薄西山 is often attributed to a famous memorial, “Chen Qing Biao” (《陈情表》), written by Li Mi (李密) during the Jin Dynasty (around 265-420 AD). In his letter to the emperor, Li Mi declined a government position by explaining he had to care for his elderly grandmother, whom he described as “日薄西山, 气息奄奄” (rì bó xī shān, qì xī yǎn yǎn) — “like the setting sun, breathing her last breaths.” This historical context cemented the idiom's association with old age and the fragility of life. In Western culture, we might say someone is “in their twilight years” or a company is “on its last legs.” While similar, these phrases are more direct. 日薄西山 is more poetic and rooted in the observation of nature, a common characteristic of Chinese chengyu. It evokes a sense of natural, inevitable decline, like the cycle of day and night, rather than just failure or weakness. It reflects a cultural perspective that sees human life and history as part of a larger, natural order.
This is a literary and formal idiom. You won't hear it in casual, everyday chat, but it's common in writing, news commentary, historical discussions, and formal speeches.