Let me first provide a brief summary of the doctrine in my own words, and then I'll paste some quotations and links to show the foundations of my summary. I'm not going to try to incorporate every single detail that could be elaborated upon in my summary, but only summarize the main body of the idea of infallibility in the Church.
The teaching authority of the Catholic Church resides in the "Magisterium," which is simply the body of bishops who govern the Church in communion with the Bishop of Rome, the Pope. God has given what I'll call the "gift of reliability" to the teachers of the Church, so that what they teach in terms of the doctrine of the church (whether of "faith" or "morals") is accurate and does not lead into error. This gift is not given to individual bishops acting alone, but only to the body of bishops as a whole--so it is possible that individual bishops, or even bishops in groups smaller than the whole of the body of bishops, might teach error, but the body of bishops as a whole can never do so. Also, the Pope, as the head of the church, has the gift of reliability given to him in his own unique office as well, so that he can never teach error when he is exercising his teaching office.
Sometimes the Church teaches a doctrine definitively--that is, it teaches a doctrine as certainly and irrevocably the correct opinion. This might happen when the bishops come together in an ecumenical council and make definitive decrees or statements, or it might happen as all the bishops in the ordinary exercise of their office agree in teaching a doctrine definitively throughout the world. The Pope might teach a doctrine definitively either by formally defining a doctrine as a dogma (this is the famed ex cathedra declaration) or simply by affirming that a doctrine is the definitive teaching of the Church. When the Church teaches something definitively, since it has the gift of reliability, Catholics are obligated to receive and accept it definitively. Sometimes, however, the Church might teach a doctrine non-definitively--that is, it might teach a doctrine in such a way that it is claimed to be true, or accurate, or good to believe or hold or practice, etc., but not in such a way that it is claimed that the final, unchangeable word on the subject has been given. The doctrine is not claimed as definitely certain or true or unchangeable in its current form. For example, the bishops or the Pope might say, "X is the best way to think about this right now," or "We should think X right now," or "So far as we can see at this point, X appears to be true," or "We should do things in this way right now," etc. There could be lots of ways such a non-definitive teaching could be given and a variety of degrees of certainty in such pronouncements--context would determine how to interpret any particular statement or teaching. A non-definitive teaching must be accepted and adhered to by Catholics as well. It must be accepted in the way and to the degree it was intended by the Church--again, interpreted by context.
The short of it is that what the Magisterium of the Catholic Church teaches is to be received as reliable and followed accordingly. We can see that one popular idea about the Church's infallibility is quite wrong--the idea that Catholics are only obliged to accept a teaching of the Church if it is proposed by a Pope in a definitive, formal, ex cathedra statement. Catholics are not at liberty to ignore or reject any teaching on doctrine or morality given to them by the Church.
Quotations and References
One of the most complete and helpful statements on this subject given by the Church recently is found in the Vatican II document Lumen Gentium, section 25:
25. Among the principal duties of bishops the preaching of the Gospel occupies an eminent place.(39*) For bishops are preachers of the faith, who lead new disciples to Christ, and they are authentic teachers, that is, teachers endowed with the authority of Christ, who preach to the people committed to them the faith they must believe and put into practice, and by the light of the Holy Spirit illustrate that faith. They bring forth from the treasury of Revelation new things and old,(164) making it bear fruit and vigilantly warding off any errors that threaten their flock.(165) Bishops, teaching in communion with the Roman Pontiff, are to be respected by all as witnesses to divine and Catholic truth. In matters of faith and morals, the bishops speak in the name of Christ and the faithful are to accept their teaching and adhere to it with a religious assent. This religious submission of mind and will must be shown in a special way to the authentic magisterium of the Roman Pontiff, even when he is not speaking ex cathedra; that is, it must be shown in such a way that his supreme magisterium is acknowledged with reverence, the judgments made by him are sincerely adhered to, according to his manifest mind and will. His mind and will in the matter may be known either from the character of the documents, from his frequent repetition of the same doctrine, or from his manner of speaking.
Although the individual bishops do not enjoy the prerogative of infallibility, they nevertheless proclaim Christ's doctrine infallibly whenever, even though dispersed through the world, but still maintaining the bond of communion among themselves and with the successor of Peter, and authentically teaching matters of faith and morals, they are in agreement on one position as definitively to be held.(40*) This is even more clearly verified when, gathered together in an ecumenical council, they are teachers and judges of faith and morals for the universal Church, whose definitions must be adhered to with the submission of faith.(41*)
And this infallibility with which the Divine Redeemer willed His Church to be endowed in defining doctrine of faith and morals, extends as far as the deposit of Revelation extends, which must be religiously guarded and faithfully expounded. And this is the infallibility which the Roman Pontiff, the head of the college of bishops, enjoys in virtue of his office, when, as the supreme shepherd and teacher of all the faithful, who confirms his brethren in their faith,(166) by a definitive act he proclaims a doctrine of faith or morals.(42*) And therefore his definitions, of themselves, and not from the consent of the Church, are justly styled irreformable, since they are pronounced with the assistance of the Holy Spirit, promised to him in blessed Peter, and therefore they need no approval of others, nor do they allow an appeal to any other judgment. For then the Roman Pontiff is not pronouncing judgment as a private person, but as the supreme teacher of the universal Church, in whom the charism of infallibility of the Church itself is individually present, he is expounding or defending a doctrine of Catholic faith.(43*) The infallibility promised to the Church resides also in the body of Bishops, when that body exercises the supreme magisterium with the successor of Peter. To these definitions the assent of the Church can never be wanting, on account of the activity of that same Holy Spirit, by which the whole flock of Christ is preserved and progresses in unity of faith.(44*)
But when either the Roman Pontiff or the Body of Bishops together with him defines a judgment, they pronounce it in accordance with Revelation itself, which all are obliged to abide by and be in conformity with, that is, the Revelation which as written or orally handed down is transmitted in its entirety through the legitimate succession of bishops and especially in care of the Roman Pontiff himself, and which under the guiding light of the Spirit of truth is religiously preserved and faithfully expounded in the Church.(45*) The Roman Pontiff and the bishops, in view of their office and the importance of the matter, by fitting means diligently strive to inquire properly into that revelation and to give apt expression to its contents;(46*) but a new public revelation they do not accept as pertaining to the divine deposit of faith.(47*)
This is from the Catechism of the Catholic Church:
888 Bishops, with priests as co-workers, have as their first task "to preach the Gospel of God to all men," in keeping with the Lord's command.415 They are "heralds of faith, who draw new disciples to Christ; they are authentic teachers" of the apostolic faith "endowed with the authority of Christ."416
889 In order to preserve the Church in the purity of the faith handed on by the apostles, Christ who is the Truth willed to confer on her a share in his own infallibility. By a "supernatural sense of faith" the People of God, under the guidance of the Church's living Magisterium, "unfailingly adheres to this faith."417
890 The mission of the Magisterium is linked to the definitive nature of the covenant established by God with his people in Christ. It is this Magisterium's task to preserve God's people from deviations and defections and to guarantee them the objective possibility of professing the true faith without error. Thus, the pastoral duty of the Magisterium is aimed at seeing to it that the People of God abides in the truth that liberates. To fulfill this service, Christ endowed the Church's shepherds with the charism of infallibility in matters of faith and morals. The exercise of this charism takes several forms:
891 "The Roman Pontiff, head of the college of bishops, enjoys this infallibility in virtue of his office, when, as supreme pastor and teacher of all the faithful - who confirms his brethren in the faith he proclaims by a definitive act a doctrine pertaining to faith or morals. . . . The infallibility promised to the Church is also present in the body of bishops when, together with Peter's successor, they exercise the supreme Magisterium," above all in an Ecumenical Council.418 When the Church through its supreme Magisterium proposes a doctrine "for belief as being divinely revealed,"419 and as the teaching of Christ, the definitions "must be adhered to with the obedience of faith."420 This infallibility extends as far as the deposit of divine Revelation itself.421
892 Divine assistance is also given to the successors of the apostles, teaching in communion with the successor of Peter, and, in a particular way, to the bishop of Rome, pastor of the whole Church, when, without arriving at an infallible definition and without pronouncing in a "definitive manner," they propose in the exercise of the ordinary Magisterium a teaching that leads to better understanding of Revelation in matters of faith and morals. To this ordinary teaching the faithful "are to adhere to it with religious assent"422 which, though distinct from the assent of faith, is nonetheless an extension of it.
In the document Humani Generis, section 20, Pope Pius XII warns against those who would ignore the ordinary teaching authority of the Church:
20. Nor must it be thought that what is expounded in Encyclical Letters does not of itself demand consent, since in writing such Letters the Popes do not exercise the supreme power of their Teaching Authority. For these matters are taught with the ordinary teaching authority, of which it is true to say: "He who heareth you, heareth me"; and generally what is expounded and inculcated in Encyclical Letters already for other reasons appertains to Catholic doctrine. But if the Supreme Pontiffs in their official documents purposely pass judgment on a matter up to that time under dispute, it is obvious that that matter, according to the mind and will of the Pontiffs, cannot be any longer considered a question open to discussion among theologians.
Further helpful information regarding the Church's understanding of her own infallibility can be found in this document, written up by the Congregation for the Doctrine of the Faith, which contains further elaborations on what sort of assent is required to the teachings of the Catholic Church. Fr. John Trigilio has provided a helpful summary of the various categories mentioned in the document here.
The Code of Canon Law also provides a helpful summary of the Church's teaching on these matters.
Finally, this article provides text from some documents which show how the infallibility of the ordinary universal magisterium of the Church has been exercised in practice regarding the issue of women's ordination.
ADDENDUM 12/14/18: I've written up a couple of articles dealing with the question of the permissibility of criticism of and dissent from Church teaching. The short one can be found here and the longer one can be found here. Also see this article on the unfailing reliability of the ordinary magisterium of the Church.