Hobbits are naturally more resistant to the influences of the ring than other races (Gandalf comments on this).
As for Sam, his resistance likely has to do with his innate goodness and loyalty. His love for Frodo helped him to overcome the pull of the Ring and his inner pureness was never fully pierced by the Ring.
The Ring's effects
Inversely, the hobbits' good-naturedness and lack of ambition makes them less susceptible to the Ring's promises of power, as in Frodo and Samwise Gamgee, who are able to handle the Ring for extended periods of time.
Originally Answered: Was Sam ever affected by the Ring in LOTR? Yes, but the damage was temporary and minimal because Sam had no desire to rule others. The Ring did make him invisible, as it did to all mortals. It also enabled him to see in the dark better, and to hear better, than he ordinarily could.
When Sam was wearing the ring, why didn't Sauron and the Nazgûl see this and come after him? Because, contrary to what Jackson depicts in his films, the Ring was not a homing beacon - outside of very specific circumstances.
As Olsen said, Sauron does not have a real body, so he is not affected in the same way. The Ring only affects mortal beings, and because Sauron is an immortal Maia spirit, he doesn't experience the same side effect of invisibility.
With how terrible and dangerous the journey to Mordor was, The Lord of the Rings ends on a relatively positive note. But still, with Frodo and Sam separating from the Fellowship, there was a very real chance that things could've gone south, and Sam would've been left to carry the One Ring.
Except for Tom Bombadil, nobody seemed to be immune to the corrupting effects of the One Ring, even powerful beings like Gandalf and Galadriel, who refused to wield it out of the knowledge that they would become like Sauron himself.
Merry and Pippin may presumably have also been very good at resisting the ring, as they are hobbits, and neither seem to have selfish ambitions nor lofty desires, so it's safe to assume that they would have passed the test unscathed.
After all, Sam's loyalty is partly a result of his servant status. Since Sam knows his place and has no ambition to rise socially, he never appears to envy Frodo's wealth or authority in the Shire. In fact, it's quite the opposite: Sam loves and admires his master, as though Frodo's honor reflects well on Sam himself.
What Makes the One Ring Different. While the previous 19 rings were crafted with the help of the Elves, the final ring, the 'One Ring to rule them all,' was crafted by Sauron alone; with the ability to dominate the other rings, the One Ring was made with some of Sauron's own power, in order to make it more powerful.
A huge part of why the hobbits can resist the Ring's power so strongly is that they were not a part of Sauron's original conquest plans. The Dark Lord saw hobbits as lesser, and they were not a race he tried to convert with his corrupted power because he saw nothing exceptional or outstanding in them.
But when watching Frodo and Sam interact, there always seemed to be a lot more there than just friendship, and that's not even counting the master-servant relationship. In the second book, Sam does say he loves Frodo.
Tolkien considered Sam a hero of the story. Psychologists have seen Sam's quest as a psychological journey of love. Tolkien's biographers have noted the resemblance of Sam's relationship with Frodo to that of military servants to British Army officers in the First World War.
It is only by chance (since they spared Gollum's life) that the Ring was destroyed. If Sam had carried the Ring, then based on what happens in the books, he would have been able to resist the temptation the Ring offered and throw the Ring into the fires with little to no hesitation.
The first is that Bilbo is a hobbit, and as such, is particularly difficult to manipulate or corrupt. Hobbits have a natural resistance to the influence of the ring, because they are fully content in their simple lives and have no desires for power or war.
The Ring has not tempted everyone. While Gandalf and Galadriel were offered it and tempted directly, others are not. Strider, Gimli, Merry, Pippin, Sam, and Legolas were in the presence of the Ring for months and did not succumb to its influence.
Aragorn was tempted by the ring, but he was able to resist it, partly because he was more alike to Elendil than any before him - Elendil was wise and friendly with the Elves. If Isildur and Elendil's positions had changed, Elendil would likely have foreseen the evil of the Ring and destroyed it.
Frodo even offers her the one ring. Galadriel admits she has long awaited the chance to seize the powerful token. But, she says, if she took it, she would become corrupted herself and rule over Middle-earth as a beautiful but tyrannical queen.
It is often thought that his mysterious origin may tie back to the Ainur, the angelic creatures who had a hand in creating Middle-earth itself. Using softer, gentler sources such as music and the forest around him, Bombadil could perform great magic to seemingly control the world, reality and nature around him.
Nevertheless, Tolkien left clues that Bombadil is a Vala, a god of Middle-Earth, specifically Aulë, the archangelic demigod who created the dwarves. Robert Foster suggested in 1978 that Bombadil is one of the Maiar, angelic beings sent from Valinor.
When Frodo shows Tom Bombadil the Ring, he amazes the Hobbits by putting the Ring on without disappearing. The reason that Tom Bombadil is not subject to the power of the Ring is that he really, truly does not desire power or ownership over any one thing.
Frodo had to carry the burden of the One Ring, but he would never have made it to Mount Doom without Sam. Sam remained positive until the very end. He believed in the good of everything around him, no matter how dark it seemed. He was the reason Frodo was able to complete the journey, and destroy the ring.
Because Sam's trust is by loyalty and free will while gollum's is by order and dominance. So when they got closer to Mount Doom, Frodo tends to rely on order over loyalty by the influence of the ring.
Because Sam is Sam, he forgives Frodo immediately and then turns his thoughts to the journey ahead. He goes and finds clothes for Frodo and whatever food he can scrounge up, and then they get the heck outta Cirith Ungol. The Watchers aren't about to let them out, though, so Sam pulls out Galadriel's phial again.