The Buddha describes the wandering in samsara due to not fully understanding and penetrating the Four Noble Truths.

Paṭhamakoṭigāma sutta - At Koṭi Village (First)

At one time, the Blessed One was dwelling among the Vajji people, in the village of Koṭi. There, the Blessed One addressed the bhikkhus: "Bhikkhus, because of not fully understanding and penetrating the Four Noble Truths, both you and I have wandered and undergone this journey of cyclic existence for a long time.

What are these four? It is because of not fully understanding and not penetrating the noble truth of suffering, bhikkhus, that both you and I have run and wandered this long course of samsara, for a very long time. It is because of not fully understanding and not penetrating the noble truth of the arising of suffering, the noble truth of the ending of suffering, and the noble truth of the way of practice leading to the ending of suffering, that both you and I have run and wandered this long course of cyclic existence, for a very long time. But now, bhikkhus, having fully understood and penetrated the noble truth of suffering, the noble truth of the arising of suffering, the noble truth of the ending of suffering, and the noble truth of the way of practice leading to the ending of suffering; the craving for existence is severed, the entanglement of becoming is destroyed; there is no more rebirth."

The Blessed One said this. Having spoken thus, the Well-Gone One further said this:

"Due to not seeing as they truly are, the Four Noble Truths; we've roamed and wandered on, through many a birth in cyclic existence.
These truths now seen, the net of becoming torn asunder; the root of suffering cut, no more is there rebirth."