Up until the 16th century Welsh male names took the form [first name] son of [father's name]. The "son of" element in Old Welsh was mab or map (which later became ap and ab) and changed with each generation. For example, the 12th century Welsh hero Rhys ap Gruffydd had a son called Maelgwn ap Rhys, who, in turn, had a son called Maelgwn ap Maelgwn. Women's names used ferch "daughter of" instead of ap "son of", as we can see with Rhys' daughters Angharad ferch Rhys and Gwenllian ferch Rhys.
It was during the reign of Henry VIII that surnames in Wales became hereditary -- the fashion starting amongst the gentry and eventually spreading to the masses. Instead of a Welshman's name being deriving directly from their own father's name, the same surname was passed down through generations. Although it is worth noting that, even up until the 19th century, some people in Wales still took their father's first name as their surname.
Welsh patronymic surnames generally take two forms: either with a genitive -s (such as Owens or Evans), or with the ab or ap element. The 'a' was dropped in vernacular speech leading to forms such as Bowen (ab Owen) and Powell (ap Hywel).