Self destruct is last resort tactic which completely destroys a starship or facility. Self destruct (or Auto destruct or Destruct Sequence) systems can be found on most if not all Federation Starfleet ships and those of many other species and governments.
Auto-destruct is usually done as a last resort, to prevent the capture of technology by foreign forces, or in the case of Federation ships, to prevent the technology from falling into the hands of those protected by the Prime Directive. In the space forces of the Federation and many galactic powers, it is an accepted fact of life that this sacrifice may need to be made for these reasons.
When the USS Europa was rammed by a Klingon ship at the Battle of the Binary Stars, Admiral Brett Anderson ordered the surviving crew to evacuate, then set the self-destruct system. The resulting explosion destroyed the Europa and the Klingon vessel. (DSC episode: "Battle at the Binary Stars")
In 2268, Commissioner Bele of Cheron V used his mental powers to commandeer the USS Enterprise and force it to his home world. To force him to relinquish control, Captain James T. Kirk activated the self-destruct sequence, which he still had full control over. With six seconds to go, Bele yielded control and Kirk canceled the self-destruct. (TOS episode: "Let That Be Your Last Battlefield")
In 2370, the USS Enterprise D was attacked by an unidentified remote controlled vessel. The Enterprise successfully blocked the vessel's controlling transmissions using an inter-receptive network, at which point the vessel self destructed. (TNG comic: "Strategy")
In the original configuration of the Constitution class starship, when the commanding officer of a ship decided to engage the auto-destruct system, he or she would have the communications officer activate the main computer tie-in to the bridge. The three senior officers - usually the Captain, First Officer, and Chief Engineer would enter a series of voice commands to set and activate the sequence.
The Captain would give the first destruct sequence, which was "Code 1,1A." The first officer would then give the second part, which was "Code 1,1A,2B." Then the chief engineer would give the third sequence, which was "Code 1B,2B,3." The computer would then announce that the sequence was complete, and would request the final sequence to activate the self-destruct sequence. The Captain would give the final sequence, which was the words "Zero-Zero-Zero Destruct Zero." Once the final code was given, the auto-destruct would begin, counting down from 30 seconds. The sequence could be aborted at any time before T-5 seconds. If the sequence was to be given, the Captain would give the code "Abort destruct sequence, code 1-2-3-continuity". (TOS episode: "Let That Be Your Last Battlefield")
In the refit Constitution class ships, the means of activating the sequence was basically the same, but the time length was increased to 60 seconds. In refit vessels two destruct methods were built into the ship. The first method was to cause all the magnetic fields around the anti-matter bottles to collapse, engulfing the ship and any nearby objects in a sun-like antimatter fireball. The said-matter/antimatter detonation would encompass a mass and surface area equivalent to the Hawaiian island Maui, (V'Ger's central core) if necessary. (TOS movie: The Motion Picture, TOS novel: Ex Machina) This method was used if the final sequence given was "Zero-Zero-Zero Destruct One." If the ship was near something to be preserved - such as another ship or planet a second system was used. In this system the antimatter was ejected from the ship. Powerful charges detonated throughout the ship, and all electrical systems were overloaded. The result was a lifeless hulk which would be useless to enemy vessels. This method was used if the final sequence given was "Zero-Zero-Zero Destruct Zero." (TOS reference: Mr. Scott's Guide to the Enterprise) It was this second method that was used to destroy the USS Enterprise in 2285. The charges first destroyed the bridge dome, then sheared off more than half the saucer section in a massive explosion. The remaining hulk was pulled into the gravity well of the Genesis Planet and streaked across the atmosphere as she burned up. (TOS movie: The Search for Spock)
Galaxy class starships were also equipped with auto-destruct systems. There were two systems used for auto-destruct on such vessels. The first, and primary method involved the shutting down of antimatter containment, plus an overload of the warp core. The resulting explosion was estimated to be equivalent to the detonation of 1,500 photon torpedoes. The secondary method involved the setting off of charges spread throughout the ship, which was estimated to be equivalent to the detonation of 1,000 photon torpedoes. This secondary method was used on the saucer section during separated flight operations or throughout the ship when the primary auto-destruct system was offline. (TNG reference: Star Trek: The Next Generation Technical Manual)
To activate the auto destruct, the two senior officers - usually the Captain and First Officer - would touch a computer panel and identify themselves to the main computer. The Captain would instruct the computer to set the auto-destruct. The First Officer would then be asked if he or she agreed with the decision. Once that agreement was given, the computer would begin the auto-destruct sequence. The auto-destruct could be canceled at any point prior to T minus 0. The computer would check to see who was on board, and could accept auto-destruct commands down to the level of operations manager. Originally, the computer was set to give a five minute countdown, but a later modification was made allowing the countdown to be modified. (TNG reference: Star Trek: The Next Generation Technical Manual; TNG episodes: "11001001", "Where Silence Has Lease")
On Intrepid class starships, the commanding officer has to enter his/her authorization code to enable the auto destruct. He/she can also determine the countdown and if it should be silent or not. But the auto-destruct system won't work if the secondary command processors have been damaged. (VOY episodes: "Dreadnought", "Deadlock", "Basics")
Nor class Cardassian space station
Either the CO or XO has to enter the needed command authorization code to activate the auto destruct. One of them can alter that code. The self destruct sequence requires the removal of the power reactor's reaction stabilizers, which causes it to overload and to destroy the station. (DS9 episodes: "Through the Looking Glass", "Civil Defense")
The method is similar to the one used on the Constitution class, except that there's no third officer who has to enter the code "1B2B3". The CO can change the countdown. (TOS video game: Starfleet Academy: Chekov's Lost Missions)
In the Romulan Star Empire, self destruct is referred to as the Final Honor sequence. A commander may request Final Honor when his or her ship is in danger of capture; after verification of the commander's identity via retinal scan, a countdown to self destruct begins. (TOS novel: Vulcan's Heart)