Dying itself is usually not painful. The pain people picture comes from the illness, not from the act of dying, and hospice and palliative care exist to treat it. This is the question people are most afraid to ask out loud, so here is the plain answer, with the evidence behind it.
This page is about expected dying, from illness or old age, the kind that gives some warning. It is not about sudden trauma. If you want the physical signs of the last days, stage by stage, read what dying actually looks like. This page is narrower. It answers whether it hurts, at each point people lie awake worrying about.