Many modified genetic codes are found in specific genomes in which one or more codons have been reassigned to a different amino acid from that in the canonical code. We present a new framework for codon reassignment that incorporates two previously proposed mechanisms (codon disappearance and ambiguous intermediate) and introduces two further mechanisms (unassigned codon and compensatory change). Our theory is based on the observation that reassignment involves a gain and a loss. The loss could be the deletion or loss of function of a tRNA or release factor. The gain could be the gain of a new type of tRNA or the gain of function of an existing tRNA due to mutation or base modification. The four mechanisms are distinguished by whether the codon disappears from the genome during the reassignment and by the order of the gain and loss events. We present simulations of the gain-loss model showing that all four mechanisms can occur within the same framework as the parameters are varied. We investigate the way the frequencies of the mechanisms are influenced by selection strengths, the number of codons undergoing reassignment, directional mutation pressure, and selection for reduced genome size.