From Wikipedia:
According to the teaching of the First Vatican Council and Catholic tradition, the conditions required for ex cathedra papal teaching are as follows:
The Roman Pontiff speaks ex cathedra, that is, when, (in the discharge of his office as shepherd and teacher of all Christians, and by virtue of his supreme apostolic authority,) he defines a doctrine concerning faith or morals to be held by the whole Church. For a teaching by a pope or ecumenical council to be recognized as infallible, the teaching must:
Be a decision of the supreme teaching authority of the Church (the Pope alone or with the College of Bishops)
Concern a doctrine of faith or morals
Bind the universal Church
Be proposed as something to hold firmly and immutably
The terminology of a definitive decree usually makes clear that this last condition is fulfilled, as through a formula such as “By the authority of Our Lord Jesus Christ and of the Blessed Apostles Peter and Paul, and by Our own authority, We declare, pronounce and define the doctrine . . . to be revealed by God and as such to be firmly and immutably held by all the faithful,” or through an accompanying anathema stating that anyone who deliberately dissents is outside the Catholic Church.