What I have learned mostly comes from the New Advent Catholic Encyclopedia on their pages about legitimation and illegitimacy.
Basically, if a child is born out of wedlock, they are illegitimate. There are many "what-ifs", and in general, these seem to always be in the favor of legitimizing the child. For example, what if for some reason the marriage is not valid but the couple believes it is? This is called a putative marriage, and children born to parents in this situation are legitimate. What if one of the parties believes the marriage is valid, in good faith? The children would still be legitimate.
Legitimation does not depend on the will of the parents, and can take place after all parties are dead. The marriage does not have to be consummated to legitimize the child.
There are different statuses of illegitimacy.
natural or naturales - illegitimate children born of unmarried people who could have been in a legitimate marriage at the time of conception or birth.
manzeres - illegitimate children born of a prostitute.
bastardi - illegitimate children born of neither a prostitute nor a concubine.
spurii - illegitimate children born of parents who either at the time of conception or at birth could NOT have been in a legitimate marriage.
ex damnnato coitu - illegitimate children born of parents who could not have been validly married both at the time of conception and the time of birth.
nothi - illegitimate children born to one married parent, and one unmarried parent.
adulterini - illegitimate children born to two married parents (who are obviously not married to each other).
incestuosi - illegitimate children born to parents related by "collateral consaguinity" or affinity. Example: a child born from a sister-brother relationship.
nefarii - illegitimate children born to parents related in the direct line of ascent or descent. Example: a child born from a mother-son or father-daughter relationship.