The blade was carried by Bilbo in The Hobbit after he found it in a Troll-hoard. Sting was found alongside Glamdring and Orcrist. Though just a knife by the standard of elves, it made a perfect short sword for a Hobbit. A typical Gondolin weapon, it glowed blue whenever Orcs/Goblins were close by. It was christened Sting by the spiders of Mirkwood Forest, many of whom were “stung” by Bilbo with it.
Just before his nephew left on his quest to Mordor, Bilbo gave Sting to Frodo.Sam then took the weapon from his (seemingly dead) master and used it to good effect against Shelob on the borders of Mordor. After the defeat of Sauronat the end of the Third Age, Frodo entrusted Sting to Sam and it became an heirloom of the Gamgee family.
Gollum, who disliked anything made by the elves, was afraid of Sting. This fear aided Bilbo when he confronted Gollum in a cave at the base of the Misty Mountains in The Hobbit (the book). It also helped Frodo and Sam subdue Gollum in The Lord of the Rings. Orcs also had an instinctive fear of these weapons and hated any who carried them.
As is fitting for a blade of Gondolin, Sting could easily cut through the webs of the offspring of Ungoliant, including the spiders of Mirkwood and the evil Shelob herself.
The only way to explain the sword’s survival through the War of Wrath is that the sword somehow was taken out of Beleriand within the 43 years after Gondolin’s fall and before the end of the First Age. This was most likely accomplished by one of the flightless dragons involved in Gondolin’s fall, most probably the dragon later to be known as Scatha the Worm. After fleeing east with the spoils of Gondolin, including Glamdring, Orcrist, and Sting, Scatha established a lair on the southern slopes of Grey Mountains (Ered Mithrin). Roughly around 2000 of the third age, Scatha was killed by Rohirrim leader Fram but the hoard was disputed by the dwarves (it undoubtedly did contain many dwarven treasures as well, like the horn gifted to Meriadoc by Eowyn). The dwarves killed Fram and made off with some of the hoard most likely including the swords of Gondolin. The swords would have been used 700 years later in the battles between the dwarves and the orcs revenging the death of Thror and culminating in the Battle of Nanduhirion (where young Thorin Oakenshield earned his name). Thus the orcs would have a fresh fear of Biter and Beater (as demonstrated by their reactions when they capture Bilbo and company). Years after the battle, the dwarven wielders of the Elvish swords were most likely relocating to Lindon during the Fell Winter of 2911 when they were waylaid unsuspectingly by trolls in the Ettenmoors. Thus the swords ultimately fell into the hands of the three trolls from The Hobbit by the end of the Third Age