The registrar personally does this via EPP by entering the command “create contact.” The EPP guide EPP Rules Policies and Protocol description .se .nu includes information on the recommended format.
However, when it comes to changing registrar, Registry Services will create the Contact ID and does that by copying the information in the existing contact to create the new contact/contact:id.