Code 2 was a Starfleet encryption protocol used in the mid-23rd century for interfleet communications.

In 2267, on stardate 3478.2, it was noted in the latest Starfleet bulletin that the Romulans had broken the encryption of Code 2, and it was therefore replaced by Code 3. As a result of aging caused by exposure to Gamma Hydra IV radiation, Captain James T. Kirk gave orders to send a message to Starfleet Command using code two because of the Romulans presence nearby. When Nyota Uhura reminded him of their having broken the code already, he changed it to Code 3, instead.

During a competency hearing, Spock questioned Uhura about this fact, noting that both her and Kirk's initials were on the bulletin, indicating both had read it.

Later, Kirk deliberately ordered that a different message be sent on Code 2 despite uhura's repeated protests. It was in fact a clever bluff in which Kirk indicated that he would self-destruct the Enterprise using a newly installed corbomite device, destroying the Romulans and establishing a dead zone with a 200 kilometer diameter. (TOS: "The Deadly Years")