J.R.R. Tolkien names the giant spider defeated by Samwise in The Two Towers Shelob.
Shelob appears in the chapter “Shelob’s Lair,” near the end of The Two Towers. She lives in a tunnel above the pass of Cirith Ungol and attacks Frodo and Sam as they try to reach Mordor. Shelob stings Frodo, but Sam uses the sword Sting and the Phial of Galadriel to drive her away.
Tolkien describes Shelob as an ancient creature descended from Ungoliant, a monstrous being from the earlier history of Arda. Ungoliant helped Melkor destroy the Two Trees of Valinor, but she is not the spider Sam fights in The Two Towers. This distinction is a common source of confusion.
Shelob’s encounter also demonstrates Sam’s courage and his loyalty to Frodo. Believing Frodo dead, Sam temporarily takes the One Ring so the quest can continue, although he later returns it when he discovers Frodo is alive.