* Proto-Indo-European (PIE): The ancestor of many European and some Asian languages, including English, had a root something like `*h₂nogʰ-`, meaning "claw, nail, or finger/toe nail."
* Proto-Germanic: This root evolved into `*naglaz` in Proto-Germanic, also meaning "nail" (both the finger/toe nail and the metal fastener).
* Old English: From Proto-Germanic, it entered Old English as `nægl`, again with the same dual meaning.
* Middle English: The word continued as `nail` in Middle English, and the spelling and pronunciation remained largely unchanged.
So, in essence, the word "nail" ultimately comes from a very ancient root associated with claws, fingernails, and toenails, and its application to metal fasteners is a later development based on the resemblance in shape and function (to grip or hold).