The prefix code is a numbered code individually assigned to each Federation starship. It is a defensive measure designed to help Starfleet personnel combat enemies who have seized control of a ship of their fleet, and to prevent enemy ships from attempting to seize control of a Starfleet vessel.
When the relevant code is entered into the computer system of another ship, that ship is able to remotely control systems on the other ship. This includes weapons and defense systems, which enables the controlling ship to reduce the seized ship's fighting capabilities in order to permit effective attacks. However, a knowledgeable enemy can take the precaution of changing the code.
This defensive feature proved a real lifesaver in the initial engagement of the Battle of the Mutara Nebula where the damaged USS Enterprise managed to drive off the USS Reliant by accessing its five-digit code, 16309 and using it to lower the Reliant's shields, allowing the few remaining phaser blasts to cause fairly moderate damage. Without the prefix code, Admiral Kirk would have been completely out of options and very likely would have been forced to surrender and perhaps have the Enterprise destroyed by the vengeful Khan. (Star Trek II: The Wrath of Khan).
In 2367, Captain Jean-Luc Picard revealed the prefix code of the USS Phoenix to Cardassian authorities when its captain, Benjamin Maxwell, waged war on the Cardassians. The code allowed a Cardassian warship to remotely disable the Phoenix's shields. Unfortunately, the Phoenix was still able to destroy the warship. (TNG: "The Wounded")
In the CD-ROM game Star Trek: 25th Anniversary (PC), the USS Enterprise uses the prefix code of a hijacked Ptolemy-class tug to lower its shields and beam a landing party aboard. In the book The Autobiography of James T. Kirk, Kirk notes that Garth of Izar took remote control of his enemy's weapons console in the Battle of Axanar, leading to the implementation of the prefix code on Federation ships to prevent the same tactic from being used against them.
In the comic book miniseries Star Trek: The Q Conflict, when the four crews are 'shuffled' to compete against each other as part of a wager between Q, Trelane, the Organians and the Metrons, Commander William T. Riker (temporarily 'reassigned' to Captain Kathryn Janeway's team) is able to help his team gain an advantage by using his knowledge of the prefix codes of the Enterprise-E's shuttles to disable the shuttle being used by Captain Jean-Luc Picard's team for the first round of the contest, causing Picard's shuttle to make a forced landing some distance from their target.