In Genesis 5 we have the generations of Adam's descendants, concluding with Noah. When speaking of Noah's ancestors, readers tend to think only of Genesis 5.
In reality, Genesis 4 is also Noah's ancestry. Just as Genesis 1 and Genesis 2 contain alternate, literally incompatible creation stories, Genesis 5 is an alternate version of the very same genealogy found in Genesis 4. The traditional Documentary Hypothesis — which posits that Genesis is comprised of four primary sources — would say that Genesis 4 comes from the 'J source', a narrative begun with Genesis 2-3. Genesis 5, along with the genealogy in Genesis 11, comes from a parallel tradition. That genealogy has been broken down into smaller segments, one of which has been inserted into Genesis by the 'P source'.
(Alternately, a somewhat similar hypothesis suggests that 'P source' Genesis 5 was a deliberate rewrite of the earlier 'non-P' Genesis 4.)
Below, you can see the similarities between the two genealogies.
A common trait of the J source is the use of overtly symbolic names for people and places, with the meaning of those names being derived from folk etymologies. The garden is in the land of Eden (delight), denoting its paradisaical nature; Adam (man) is the first man; Eve (lifegiver) gives birth to new life; Cain (possession) is Eve's possession and, as a farmer, possesses land; Abel (breath/vain) is a herdsman, and lives a brief life.
This trait continues into Genesis 4 with Cain's son. Although the 'J source' of Genesis 2-4 explicitly has Adam and Eve as the first two humans, other people now inexplicably exist, both within and beyond the borders of the land of Eden. The curse on Adam that he would struggle to farm the earth is made worse for Cain, where the earth will produce nothing for his efforts (4.11-12). Cain, afraid that people will avenge his only brother's death, wanders off to the land of Nod (wandering). There, Cain has a son named Enoch (dedication), then builds a city, dedicating it to his son by naming it after him. Enoch also has a son, naming him Irad (fugitive).
As we flip the page the writing style in Genesis 5 changes drastically. We discover a genealogy comprised of the same names we just read, but slightly respelled and rearranged: Cain, now Enosh's son, adds one letter to become Cainan; Irad drops one letter to become Yared; Mehuyael and Methushael's names are fudged slightly to become Mahalalel and Methushelah; Enoch and Lamech's names remain identical. By the time this book has been written, Enoch has become the subject of a mysterious story where he has such favor with God that he is apparently 'raptured' centuries before he would otherwise have died. To reflect Enoch's importance, he and Mehuyael/Mahalalel are switched in the order, which places Enoch as the seventh from Adam.
The names are obvious variations of each other, with only minor spelling and pronunciation differences (indicated in red).
After the lengthy presentation of the activity of Cain and his descendants, Genesis 4 concludes rather suddenly with the birth of a third son, Seth, to Adam and Eve, who in turn brings them a grandson, Enosh. Though the third son's name is given the overt symbolism normally found in J, the brevity of Seth and Enosh's births is jolting. Between that and the style differing from the surrounding text, these two verses are taken as the work of a redactor, inserted here to create a bridge between Cain's genealogy in chapter 4 and the alternate genealogy in chapter 5.
Genesis 5's genealogy concludes with Lamech's son Noah, who is tenth in the list. Before being stitched onto Genesis 4, this list of ten generations likely came from a single document that consisted of Genesis 5, 9.28-29, and 11.20-26 (and possibly more).
This overarching genealogy included a division of the world into two primordial ages, each lasting ten generations. The first age lasted from creation to the flood, with Noah as the tenth generation, marking the transition into the second age, which lasted from the flood to the covenant, giving Abram as the tenth generation.
Many readers are also familiar with the incredible lifespans of these ancient generations. The pre-flood patriarchs live for hundreds of years, but after the flood those lifespans rapidly decrease. This fits well with a trope seen across ancient mythologies; namely, that the pre-flood world had a different character from the post-flood world. In the Sumerian King List, the regents of Sumer ruled for tens of thousands of years before the flood; after, the first post-flood kings rule on average for 'only' a thousand years each, and the length of successive kings' rules continues to decline until the vast majority of them rule for only decade or few.
The two genealogies in Genesis 4 and 5 are the same genealogy, with the latter likely a rewritten version of the former. The latter genealogy originated from a longer list that focused on the pre- and post-flood generations of humanity; this list has been broken up across several chapters of Genesis.