姓氏 refers to surname, and 名字 refers to personal name.
But I’ve heard people using the separate characters to talk about surnames and personal names.
For example:
我的中文老师姓姚
林氏集团 (Lin’s Corporation, like one of those companies named after their founder)
她名叫小丽
字: I’m not too sure about this one, but I know 李白’s 字 is 太白
What is the difference between all these?