How do you actually carry out serial number logic for your software?

For example, I have software and I want to protect each distribution with a serial number.