Sam was cocksure, and deep down a little conceited; but his conceit had been transformed by his devotion to Frodo. He did not think of himself as heroic or even brave, or in any way admirable - except in his service and loyalty to his master. That had an ingredient (probably inevitable) of pride and possessiveness: it is difficult to exclude it from the devotion of those who perform such service. In any case it prevented him from fully understanding the master that he loved, and from following him in his gradual education to the nobility of service to the unlovable and of perception of damaged good in the corrupt. He plainly did not fully understand Frodo's motives or his distress inthe incident of the Forbidden Pool. If he had understood better what was going on between Frodo and Gollum, things might have turned out differently in the end. For me perhaps the most tragic moment in the Tale comes in II 323 ff. when Sam fails to note the complete change in Gollum's tone and aspect. 'Nothing,nothing', said Gollum softly. 'Nice master!'. His repentance is blighted and all Frodo's pity is (in a sense) wasted. Shelob's lair became inevitable."
Tolkien, Letter No. 246