Punishment should increase the overall amount of happiness in the world and create a better society.In Beccaria's time, criminal punishment was often based on retribution. Deterrence is a type of prevention meaning that the threat of punishment outweighs the urge to commit a crime.
Retribution is based on the old adage, 'an eye for an eye'. Beccaria felt that deterrence provided the most use for society.
Next, the punishment must be closely associated to the crime.
This means the punishment must be swift, or administered promptly after the crime.
To that end, the punishment need not be any more severe than what is needed to outweigh the advantages of the crime.
For example, it's not useful to give life in prison for a shoplifting case when the shoplifter will be sufficiently deterred by the threat of a month in jail.