Only God is truly fully infallible in every possible way, without limit. Sacred Tradition and Sacred Scripture (also called the Deposit of Faith) are infallible, in all that they assert as true, on matters of faith, morals, salvation, and all other topics about which they make an assertion. Tradition and Scripture are infallible because they constitute Divine Revelation from God — the Word of God is always entirely infallible.
The Magisterium has a limited gift of infallibility from God. The Magisterium is the ability and authority of the Pope and the Bishops to teach from Sacred Tradition and Sacred Scripture. The Magisterium teaches infallibly in any of three ways:
1) Papal Infallibility — solemn definitions of the Pope
2) Conciliar Infallibility — solemn definitions of an Ecumenical Council
3) ordinary and universal Magisterium — when the Pope and the body of Bishops dispersed through the world are in agreement on one position, on a matter of faith or morals, definitively to be held.
Infallible teachings are irreformable and inerrant; there is no possibility of error.
Right reason is infallible, that is to say, when the gift of reason, given by God to human persons, is used correctly, it arrives with certitude at objective truths. However, the reason of fallen sinners, living in a sinful world, is particularly prone to error.
However, the Church is not infallible in all that She says and does. Outside of the three ways that the Magisterium teaches infallibly, all other teachings of the Magisterium are non-infallible and non-irreformable; there is a possibility of error and reform.
And the Church has two types of authority:
1) spiritual authority, which is the teaching authority of the Magisterium
2) temporal authority, which is the authority to issue rules and rulings
The spiritual authority teaches doctrines, but the temporal authority rules on matters of discipline. The temporal authority of the Church is exercised by judgments of the prudential order, not by interpreting and teaching from infallible Divine Revelation. And so the temporal authority is generally fallible — except in the case of dogmatic facts (e.g. that Vatican II is a valid Council, that the current succession of Popes are each valid Popes, etc.).
Can a Pope ever fall into heresy? Not at all. For, in addition to the gift of infallibility, the Church also has the gift of indefectibility, meaning that the Church can never go astray from the path of salvation, can never cease to be other than the body of Christ on earth, and can never lead the faithful away from the path of salvation — despite the sins of its members and of its leaders, and despite the possibility of error when the Church is not teaching infallibly. If a Pope could ever possibly fall into apostasy or heresy or schism or idolatry, then the Church would not be indefectible and the Magisterium would not be able to teach infallibly. The gifts from God to the Church of infallibility and indefectibility prevent any Pope from falling into certain few types of sin (including the sin of heresy), even privately, even interiorly in his heart and mind.
What would happen if the Cardinals elected a Bishop who was a heretic to be Pope? Three things are needed for a valid Pope:
1) ordination as Bishop
2) valid election
3) acceptance of the office by the elected person
If a heretic were validly elected, God would vanquish all heresy from that man by his act of free will in accepting the office and by the grace of God. Similarly, no Pope can ever fall into heresy during his reign as Pope because the act of his free will in continuing to accept the office (rather than validly resigning) and the grace of God prevents this type of sin.