While more can always be written, variations on this question get asked in this sub pretty frequently, and I have answered it before here.
That previous answer is specific to Europe and European-influenced cultures. Maybe someone else can provide information on the history of surnames/family names/"last names" in other cultures.