The book I suggested to you, The History of the Catholic Church, expands on this topic but here is a quick answer.
en.wikipedia.org/wiki/Pope_Linus
When we die there are three options, heaven, purgatory, or hell. This is my understanding of the teaching so it may not perfectly align with someone with more theological knowledge than I have. Very few people go straight to heaven although there are those we believe have, the saints being among them. Most people will spend some time in purgatory prior to going to heaven. Purgatory is not a punishment, nor is it a negative experience. I once heard a priest say all those in purgatory will eventually get to heaven. While in purgatory we are able to leave behind any attachments to worldly goods, bad habits, secular thinking, an so on and become purged. We are cleansed of all sins and are able to place all of our heart, mind, & soul in the hands of God.
Of course some will have more work to do than others and there is no way for us to know what it will be. Because we are human and have a fallen nature we are unable to become perfect while in the world. Perfection is needed for heaven and we obtain this perfection through the process of purgation.
I look forward to purgatory, although I would like to not go for a couple more decades, because then I will truly be able to do what suffering I must in order to be in the presence of God. While I do not know what that suffering will be like it can’t be worse than the suffering here on earth knowing I fail God every day, and every day I must ask for forgiveness.
For those who did not have a chance to hear the gospel, or those who do not out right reject God, we believe in the mercy of God to save these souls. Since none of us have been to heaven & back it’s something we just can’t know. It is a mystery and one we can live with. We have a loving and merciful God. We have to place our trust in God.