The Roman Catholic Church follows the guidance handed to it by Christ Himself, in that those who descend from the Apostles (the Bishops) and in particular Peter (the Popes) determine what is and is not to be taught.
Organizationally, this group forms the Magisterium, led by the Pope. What they say goes.
They base their determinations after prayerful and extensive reading of the Scriptures and examination of the Sacred Tradition handed down from the Apostles. Our document trail, including the books that have become Canon as well as works by the earliest Church Fathers, go all the way back to the first century. The RCC was the body that compiled the Bible as we know it today.
For clarity: what they teach IS NOT PERMITTED to violate Scripture, and Sacred Tradition is limited EXCLUSIVELY to that taught by the Apostles themselves.
We know they are inerrant in their teachings because the Holy Spirit and Christ Himself WILL NOT PERMIT them to err on teachings of faith and morality, even though they (the Bishops and Pope) are imperfect sinners just like the rest of us. We are assured of this by Christ Himself when He says that "the gates of hell will not prevail against" His Church.
Therefore, we know that what comes from the Magisterium is Inerrantly taught by Christ's protection. What they say goes. This is why one can be assured that one Catholic Church is essentially identical to every other Catholic Church around the world.
One last note: Infallibility does not provide the freedom one might think. Once something has been established as being Infallible Teaching, it cannot be rescinded later. This is why the Church takes great care when promulgating Inerrant doctrine. I believe the last time that happened was back in the 60's, although I may be mistaken on that point.