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.
Active cloaking devices are fundamentally unrealistic - if a ship bent light around itself, it could not be seen, but it would also be blind. The same would apply to other methods of detection; if the ship avoids those signals, then it can't receive those signals, either.
If a cloak somehow "traps" sensor pulses, it will accumulate heat. This problem is worsened by the need to trap waste heat from the ship's own power supplies. A cloaked ship using the gigawatt-range power supplies typical of science fiction starships would cook its crew in short order.
Cloaking Devices in Star Trek
A cloaking device manipulates a starship's shields to bend light around the starship, making it effectively invisible. Advanced cloaks affect high-tech sensor emissions similarly, making the the ship invisible to many other forms of detection, as well.
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 are usually used for stealth, and their combat use is usually limited 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 cloaked Romulan vessel was completely invisible to visible light and targeting scanners, but she could still be detected with subspace 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.
Later, as part of an ongoing technology-sharing program, the Klingons gained cloaking technology and Romulans abandoned their existing warbird design in favor of Klingon designs like the D-7. 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. 
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 . Romulan Warbirds were also able to approach the station completely unseen and decloak within several kilometers, despite the station being at battle stations, with a Klingon fleet and Federation vessels all within range and expecting a Dominion attack.
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. Despite the ban, 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.
Cloaking devices have high power requirements. Consequently, depending on their power sources, cloaked vessels are usually weakly shielded, if shielded at all. Similarly, cloaked ships have relatively little power available for their weapon systems. The initial Romulan cloaking device was so power intensive that it nearly drained the energy reserves of the Romulan Bird of Prey during its battle with the Enterprise in "Balance of Terror". One can speculate that the primary reason a typical cloaked vessel cannot fire while cloaked is that 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.
Because cloaking devices are integrated into a ship's shield systems, cloaking and decloaking usually creates a window of vulnerability in which shields are not functional; Commander Riker exploited such a weakness in Star Trek: Generations to destroy a Klingon Bird of Prey.
Romulan officers do not consider their cloaking technology sufficient to bypass the prepared defenses at the Federation border.
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 have been spotted by the naked eye, such as in Star Trek III: The Search for Spock, or the external visuals in Star Trek: Nemesis.
Cloaking, as described in Star Trek, has all of the realism issues described at the beginning of this article. Dumping waste energy into subspace won't solve the problem, since Star Trek ships have subspace sensors that would be expected to detect such emissions, foiling the cloak.
Cloaking Devices in Star Wars
Cloaking devices have occasionally been mentioned in the Star Wars movies, but never actually seen in operation. In Star Wars: The Empire Strikes Back, when the ISD Avenger loses track of the Millennium Falcon, Captain Needa questions the possibility that his target engaged a cloaking device because a ship that small shouldn't have one. In Star Wars: The Phantom Menace, Qui-Gon Jinn asks if Queen Amidala's yacht has a cloaking device, but Captain Panaka informs him that it does not.
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.
In Star Wars: The Clone Wars, the second-season episode "Cat and Mouse" shows a prototype cloaking device. This cloak made the ship invisible to normal sight and most sensors. There was a distinct shimmering effect when engaging or disengaging the cloak. This cloak allowed a trace amount of "magnetic energy" to escape, which eventually allowed the cloaked ship to be tracked by enemy missiles. Unlike the devices used in Heir to the Empire, this cloak was not "double-blind", thus possibly explaining the leakage and its status as an important, cutting-edge prototype.
While not much more realistic than cloaks from other settings, the "double-blind" aspect of Star Wars cloaks is a slight improvement in realism over cloaks that allow a ship to hide from sight and sensors without experiencing any limitations on its own sensor capacity. The "magnetic energy" leakage of the device from The Clone Wars also improves realism: if the ship is absorbing enough energy to see, it needs to release a similar amount to avoid heating up.
Cloaking Devices in Stargate
The Goa'uld posses some level of cloaking technology which can be used on both a human scale as well as on the scale of small spacecraft such as Al'kesh and Tel'taks. For the most part cloaking devices on the scale of capital ships such as Ha'tak are beyond the technical capacity of the Goa'uld, with the notable exception of that of Sokar's realm. Puddle Jumpers are also equipped with cloaking devices which can be interfaced with Atlantis' shields. In late 2006, Daniel Jackson gave the USAF Odyssey the ability to cloak. The Asurans also fielded cloaking device on their warships.