A cloaking device is a form of stealth technology that uses selective bending of light (and other forms of energy) to render a starship or other object completely invisible to the electromagnetic spectrum and most sensors. It has been encountered in varying forms over the centuries.
Cloaking Devices in Star Trek
The purpose of a cloak is to prevent detection before combat and when fleeing combat, and cloaking devices have been able to hide vessels from all but the most advanced scanners and tracking systems. Cloaking devices have been usually used for stealth, and its combat use is limited usually to moving into position for an ambush. For example, the early cloaking device was a perfect supplement to the Romulan plasma weapon allowing the Bird of Prey to approach as close as possible to deploy the limited-range weapon for maximum effectiveness.
The early cloaks were proprietary technology of the Romulans. In the first recorded instance of military use of a cloaking device against a Starfleet vessel, the Romulan cloaking device was completely invisible to visible light and standard optical scanners, but she could still be detected on motion sensors and was tracked in this manner by the Enterprise throughout the engagement near the Neutral Zone. This form of tracking proved poor for targeting and precision movement, forcing Captain Kirk to lay down a pattern of weapon fire in hopes of catching his target. (TOS, "Balance of Terror")
Later on as part of an ongoing technology-sharing program, the Klingons gained the cloaking device and Romulans abandoned their existing warbird design in favor of Klingon vessels like the D-7 (TOS, "The Enterprise Incident"). Klingons began using cloaking devices on their own Bird of Prey designs, as seen in the Genesis incident when Kruge's Bird of Prey penetrated deep into Federation space destroying the USS Grissom and ambushing the Enterprise utilizing the cloaking device. (Star Trek III: The Search for Spock)
The performance characteristics of cloaking devices have changed over time. For instance, the Klingon cloaking device in ST3 created a visible distortion effect when the ship was in motion, but it successfully hid the ship from all other forms of detection. As seen in the TNG era and onward, the cloaking devices available to the Klingons and Romulans have grown much more sophisticated. Klingons cloaks are so advanced that even when cloaking and decloaking within several kilometers of Deep Space Nine, the sensor suites could not accurately track the Klingon vessels (DS9, "Way of the Warrior"). Romulan Warbirds were also able to approach the station completely unseen and decloak within several kilometers despite the station being at battle stations, a Klingon fleet and Federation vessels all within range and expecting a Dominion attack. (DS9, "By Inferno's Light")
One of the most recent evolutions of cloaking technology was seen twice, once by Klingon design and another by the Romulans. General Chang of the Klingon Empire utilized a Bird of Prey that could fire while cloaked, a notorious limitation of most cloaking devices. This Bird of Prey was destroyed over Khitomer and was the only known proto-type. We have not seen a cloaked Klingon ship accomplish this since. The cloaking device used on the Scimitar also allowed the vessel to fire while cloaked and was used with devastating effectiveness against the Enterprise-E. This may be the natural progression of the device should greater enhancements be made in the future, but advances in sensor technology may defeat this cloaking system, as apparently occurred with Chang's now-obsolete cloak.
Cloaking Device Politics
The Federation is banned from developing cloaking devices by the Treaty of Algeron with the Romulan Empire. The circumstances under which the Federation agreed to hamstring itself by not developing this technology are unknown. Also, the Federation did produce one illegal cloaking device - one that is a quantum leap ahead of anything produced by either the Romulans or the Klingons - a phase cloak that allows a vessel to pass through solid matter.
In general, depending on their power sources, cloaked vessels are not shielded. Cloaking and decloaking generally creates a window of vulnerability, exploited by Riker in Star Trek: Generations to destroy a Klingon Bird of Prey.
The initial Romulan cloaking device was extremely power intensive and nearly drained the power reserves of the Bird of Prey during its battle with the Enterprise in "Balance of Terror". One can speculate that the primary reason a cloaked vessel cannot fire while cloaked may be because too much power is required for maintaining the cloak to properly power the weapons systems. This is hinted at when Captain Kruge warns his ship's gunner to transfer power to the weapons "at my command," perhaps concerned that power would be transfered too soon, thus compromising the cloak. (Star Trek III: Search for Spock)
Romulan officers do not consider the cloaking technology sufficient to bypass the prepared defenses at the Federation border (TNG, Face of the Enemy).
A cloaking device can be defeated using a "tachyon net"; a cloaked ship trying to pass through the net will still interrupt one of the tachyon beams being transmitted among the ships participating in the net, revealing its location.
In certain rare instances, cloaked vessels can be spotted by the naked eye, such as in Star Trek III: The Search for Spock, or the external visuals in Star Trek: Nemesis.
Cloaking Devices in Star Wars
Cloaking devices have been mentioned a couple of times in the Star Wars movies, but they have only been described in use in post-movie novels.
In Star Wars: The Empire Strikes Back, when the ISD Avenger loses track of the Millenium Falcon, Captain Needa dismisses the possibility that his target engaged a cloaking device because the target ship is too small to have one.
In the Heir to the Empire series of novels by Timothy Zahn, Grand Admiral Thrawn employs cloaking devices in several ways. According to these novels, a ship can avoid detection with a cloaking device, but the cloaked ship is also completely blind, limiting the usefulness of the device.