Before us is Mishnah 12 in the third chapter of Maseches Kiddushin. The Mishnah lays down four rules for determining the lineage of a child, and they are divided according to the status of the kiddushin between the man and the woman: whether the kiddushin take effect, and whether a transgression is involved in them.
"Kol makom she'yesh kiddushin v'ein aveirah":
A situation in which the kiddushin are valid and take effect, and no sin at all is involved in the marriage. Regarding this the Mishnah says "havlad holech achar hazachar" - the child's lineage follows the father.
And what is the example of this? "Zo kohenes, leviyah v'yisre'elis shenisu l'chohen, l'levi ul'yisrael" - a woman who is the daughter of a kohen, the daughter of a Levi, or the daughter of a Yisrael who married a kohen, a Levi, or a Yisrael: the child will be a kohen, a Levi, or a Yisrael according to the father, and not according to the mother.
"Kol makom she'yesh kiddushin v'yesh aveirah":
A situation in which the kiddushin take effect, but a transgression is bound up with them. Regarding this the Mishnah says "havlad holech achar hapagum" - the child follows the flawed side of the match, whether one of the parents was flawed to begin with or whether the flaw was created by this very marriage.
"Almanah l'chohen gadol" - a widow who married a Kohen Gadol, a forbidden marriage.
"Gerushah vachalutzah l'chohen hedyot" - a woman who was divorced or who underwent chalitzah and married an ordinary kohen, which is likewise forbidden. The child does not, of course, become a widow, a divorcee, or a chalutzah, but he or she will be a chalal or chalalah as a result of this marriage.
"Mamzeres unesinah l'yisrael, uvas yisrael l'mamzer ul'nasin" - a mamzeres or a nesinah who married a Yisrael, or the daughter of a Yisrael who married a mamzer or a nasin: the child will be a mamzer or a nasin, a mamzeres or a nesinah.
"Kol mi she'ein lo aleha kiddushin, v'yesh lo al acheirim kiddushin":
A man who cannot betroth this particular woman, but who is able to betroth other women, and the woman too is able to be betrothed to others - since both sides are fit for kiddushin, just not with each other. Regarding this the Mishnah says "havlad mamzer".
And what is the example of this? "Zeh haba al achas mikol ha'arayos shebaTorah" - one who cohabits with one of the arayos stated in the Torah, with whom specifically kiddushin do not take effect, and the child born of such a union is a mamzer.
"Kol mi she'ein lo aleha v'lo al acheirim kiddushin":
A woman with whom kiddushin do not take effect at all, neither with this man nor with any other person. Regarding this the Mishnah says "havlad k'mosah" - the child follows the status of the mother.
And what is the example of this? "Zeh v'lad shifchah v'nochris" - the child of a maidservant will be a slave or a maidservant, whether it is a boy or a girl, and the child of a non-Jewish woman is not Jewish. In both of these cases the lineage is determined by the mother.
In summary: The Mishnah teaches four rules regarding the lineage of a child. When there are kiddushin and no transgression - the child follows the father. When there are kiddushin and there is a transgression - the child follows the flawed member of the couple. When kiddushin do not take effect between them but each of them can effect kiddushin with others, as in the case of the arayos of the Torah - the child is a mamzer. And when kiddushin do not take effect with her at all, as with a maidservant or a non-Jewish woman - the child is like her, following the mother.