A code was a system to convert a piece of information into another form. Codes were most often used to send messages or define situations. Codes could be decrypted using a code key. (VOY: "The Killing Game")
An early code that was used for communication on Earth during the 19th century was Morse code. (Star Trek V: The Final Frontier; TNG: "A Fistful of Datas")
The intersat code was used in the 21st century for inter-stellar communications. (TAS: "The Terratin Incident")
Early computer systems on Earth were based on binary code, and later Federation systems could even support trinary code. (VOY: "Hope and Fear")
Codes were often used to encrypt information, including the Federation's Code 2 and Code 3 in the 23rd century; the former had been broken by the Romulans by stardate 3478.2, and thus was replaced by the latter. (TOS: "The Deadly Years")
Many other codes were simply used to transmit information quickly, including Code One alert to indicate a declaration of war or disaster, (TOS: "Errand of Mercy") Code 710 to indicate planetary quarantine, (TOS: "A Taste of Armageddon") Code 1-Alpha-Zero for a ship in distress, (TNG: "Relics") Code Factor 1 for a possible invasion of the Federation, (TOS: "The Alternative Factor") code blue, or blue alert, used to indicate a change in starship flight status, (TNG: "Brothers") code white resuscitation to indicate the need to resuscitate a dead individual, (VOY: "Initiations") Emergency Code 1 for intruder alert, (TNG: "The High Ground") and Transporter Code 14 to destroy an object in a transporter beam. (TNG: "Captain's Holiday")
Codes could also be used to designate messages for specific individuals, such as code 47 meaning "for captain's eyes only." (TNG: "Conspiracy")
Critical ship systems required pass-phrase access in the form of prefix codes (Star Trek II: The Wrath of Khan; TNG: "The Wounded") and authorization codes. (Star Trek: First Contact; VOY: "Deadlock", "Dreadnought", "Cathexis", "Renaissance Man"; TNG: "Chain Of Command, Part I")
In 2151, the Vulcans sent encrypted coded secret messages to Enterprise NX-01. It was decrypted by communications officer Hoshi Sato and identified as private Vulcan letters sent to T'Pol. (ENT: "Breaking the Ice")
In August 2151, ECS Fortunate first officer Matthew Ryan interrogated and tortured a Nausicaan prisoner to get the codes for the shield frequencies of his ship. (ENT: "Fortunate Son")