The first Vatican council in 1869-70 in its Pastor aeternus decree declared that the Pope is infallible when he speaks “ex cathedra” meaning, “from the papal throne” on matters of faith and morals.
This declaration does not cover all grounds; it was made with regards to the faith and morals of the Church. What does this mean? It means that the Pope as far as we know, can be either right or wrong in his opinions or statements regarding issues outside of faith and morals. For instance, he could say that Lionel Messi is a better footballer than Cristiano Ronaldo. With such a statement, you cannot involve the Pope’s infallibility because football (sports generally) has no relationship with faith and morals.
We must understand first that the Pope is human and so he is prone to make mistakes in his predictions, perceptions and opinions sometimes. But then, if whatever assertions he makes is related to issues of faith and morals and he officially states it from his papal throne, he is infallible because he makes such assertions with the guidance of the Holy Spirit who prevents him from leading the Church astray.
Note that his infallibility is held in effect when his statement is officially made in public by his authority. This means every other informal comment he makes does not count automatically as infallible.
On close observation, infallibility isn’t seen coming to play only when the Pope makes decrees binding to the whole Church. It is also seen in cases where the ecumenical council of bishops with the Pope issue doctrinal or moral decrees. Also, when the Pope (or bishops) emphasizes and re-emphasizes the doctrinal and moral teachings of the Church. So, infallibility also extends to the bishops given that they teach what the Church has always taught throughout the ages such as the Divinity of Christ and the Bodily Resurrection of Christ.