What the Catholic Church teaches:
“The Roman Pontiff when he speaks ex cathedra, that is, when acting in the office of shepherd and teacher of all Christians, he defines, by virtue of his supreme apostolic authority, doctrine concerning faith and morals to be held by the universal Church, possesses through the divine assistance promised to him in the person of St. Peter, the infallibility with which the divine Redeemer willed his Church to be endowed in defining doctrine concerning faith or morals; and that such definitions are therefore irreformable of themselves, and not from the consent of the Church.” ~ First Vatican Council, Dogmatic Constituation I on the Church of Christ IV
Basically,what that means is that the pope is considered to speak under divine guidance of the Holy Spirit on issues of faith and morals, when he is speaking ex cathedra, or "from the chair of Peter".
Infallibility is NOT the same thing as impeccability. The pope commits sins just like everyone else. In fact, he participates in the sacrament of reconciliation very regularly. If he's going to confession that often, he has to have something to confess!
Also, infallibility does not mean that everything that comes out of the pope's mouth when he teaches must be accepted as absolute truth. He must be speaking specifically ex cathedra. When a pope speaks from the chair of Peter, he is knowingly and willingly speaking with the authority passed down to him from the Apostle Peter.
This idea of infallibility fulfills what Jesus said in Matthew's Gospel:
Matthew 16:18 ~ And I say also unto thee, that thou art Peter, and upon this rock I will build my church; and the gates of hell shall not prevail against it.
Jesus promised that "the gates of hell shall not prevail" against His Church. In other words, He promised that He would preserve His Church on earth from lies. This is something in which the Catholic Church differs from so many different Protestant denominations. We believe that Jesus would not allow His Church to teach something that is not true.
1 Timothy 3:15 ~ But if I tarry long, that thou mayest know how thou oughtest to behave thyself in the house of God, which is the church of the living God, the pillar and ground of the truth.
Here, Paul calls the church "the pillar and ground of the truth". That raises an interesting question. Can something that is "the pillar and ground of the truth" teach error?
Now, there have been more than a few popes (and priests and bishops and cardinals...) who have been very corrupt. But, that does NOT mean that the Church itself has been corrupt. Thankfully, those popes that did lead sinful lives had no interest whatsoever in teaching on faith and morals. They never spoke heresy from Peter's chair. It just shows how God preserved His Church, even when evil leaders came into positions of authority. In fact, these popes could be compared to the scribes and pharisees in the New Testament, or even the unfaithful priests such as Eli and his sons in the Old Testament. Just because they weren't faithful to God's command doesn't mean that the Israelites weren't still God's chosen people. Really, it's precisely because the Israelites were God's chosen people that they were subject to so many spiritual attacks by the Devil.
Jesus gave a promise to His Apostles:
John 16:13 ~ Howbeit when he, the Spirit of truth, is come, he will guide you into all truth: for he shall not speak of himself; but whatsoever he shall hear, that he shall speak: and he will show you things to come.
He promised the Apostles that the Holy Spirit would guide them into all truth.
Some people might say that a human can't possibly speak infallibly, but that only God can. We believe that it is God who gives the power to the pope to speak without error in order that His Church might be preserved. God inspired the men who wrote the Scriptures to write without error. Why would he not inspire the pope to an infallible interpretation of that infallible Scripture?
But, the thing we have to remember, first and foremost, is that all truth is ultimately defined in Jesus Christ.
John 14:6 ~ Jesus saith unto him, I am the way, the truth, and the life: no man cometh to the Father, but by me.
And that is precisely why the Church exists. Not to distract people from Christ, but to guide us closer to Him.
Pax Christi,
~the Catholic apologist

