To supplement the out-of-universe answer and the in-universe answer, I can offer a combined in/out answer. Tolkien certainly modeled Samwise on people he knew in his own life and considered to be extremely heroic and admirable:
My ‘Samwise’ is indeed (as you note) largely a reflexion of the English soldier ...the memory of the privates and my batmen that I knew in the 1914 War, and recognized as so far superior to myself.
― The Letters of J.R.R. Tolkien
The 1914 war, of course, was the First World War; batmen were enlisted men who were assigned to be servants to officers. They did the same sort of things Sam does for Frodo - acting as messengers, valets, preparing meals and tea, looking after horses, uniforms, and other property, and tending to their officer's personal affairs. In a very real way, Sam in fact is Frodo's batman.
As far as the text is concerned, few characters in LotR - if any - are described as being as heroic, determined, steadfast, loyal, virtuous, humble, noble, and resolute, to the degree that - and as consistently as - Sam is.
Humility is one of his most significant attributes, in Tolkien's eyes. Tolkien was careful to portray humility as the most desirable quality a person can have; in Tolkien's universe, humility is what makes good men great. The difference between Boromir, who fell victim to the temptation of the Ring, and his brother Faramir, who easily withstood the same temptation, is humility: Faramir was humble, where his brother was vainglorious and proud.
In a similar vein, Sauron was good, then fell under the influence of the evil Melkor. When Melkor was defeated, Sauron repented and was offered a chance at redemption, if he would agree to submit himself to the judgement of the Valar and Maiar; Sauron wrestled with his pride, wanting to redeem himself, but in the end, his pride won out. He couldn't bring himself to accept the humiliation of facing judgement, and returned to his evil ways; only then, according to Tolkien, had he truly and irreversibly fallen from grace. And in the end, his pride was his ruin: Frodo was only able to destroy the Ring was because of Sauron's overconfidence. So confident was Sauron in the Ring's ability to corrupt anyone who held it that he never considered the possibility that anyone would try to destroy it. This is what Tolkien meant when he wrote that, as soon as Frodo claimed the Ring inside the Crack of Doom, Sauron's folly was laid bare to him. Only then did he realize that he had allowed his arrogance and pride to blind him.
The opposite of pride and arrogance is, of course, humility. And this Samwise Gamgee has in spades. He is constantly doubting himself; chastising himself (as his father used to do, and often in the same words his father used) for his every supposed misstep; comparing himself - always unfavorably - to most everyone he meets; second-guessing himself; engaging in self-deprecating humor; and so on. When Sam asks Frodo if he thinks there will be stories written about their adventures, and describes how people might one day speak of the great hobbit hero Frodo, Frodo suggests that readers would be more interested in "Samwise the Stout-hearted"; Sam is so incapable of seeing any virtue in himself that he immediately assumes that Frodo is mocking him and says, "Mr. Frodo, you shouldn't make fun. I was serious".
[Sam] did not think of himself as heroic or even brave, or in any way admirable – except in his service and loyalty to his master.
-J.R.R. Tolkien, Letter 329.
To put it simply, Tolkien believed that heroism and humility were inextricably intertwined - almost synonymous, even - and no one in his story is as humble as little Samwise Gamgee. Others are heroic in their own way too, of course, but none so much as Sam. When Frodo tries to leave the Fellowship on his own, Samwise is the only one who realizes what Frodo means to do. He runs after his beloved master and, although he can't swim, throws himself into the river to reach Frodo's boat, nearly drowning in the process. When Frodo falters, it is always Sam who picks him up. When Frodo appears to have been killed by Shelob, Sam overcomes his terror and selflessly throws himself at the horrible beast, eventually managing to inflict far greater damage upon the ancient monster than she herself ever considered possible. Sam is then torn between his desire to remain by his fallen master's side and his knowledge that the Ring must be destroyed at all costs; he eventually decides to bear the Ring to Mount Doom alone, but is drawn back to defend Frodo's body after it is discovered by Orcs. He then single-handedly fights off a large group of Orcs and rescues Frodo from their tower. When Frodo collapses and can walk no further, Sam picks him up and carries him to the Crack of Doom. When they are finally inside the volcano, Sam remains strong and determined, while Frodo falters at the last moment and claims the Ring as his own.
Sam is heroic precisely because he doesn't think he is a hero, or ever could be. He is all the things he thinks he is not. He thinks he is stupid, when in fact he is wise. He thinks he is weak when in fact he is incredibly strong. He thinks he is a coward when he has unparalleled courage. He thinks he is a burden when he is actually the driving force behind Frodo's mission. He thinks he does everything wrong when in fact he is the reason the quest didn't go off the rails.
Tolkien said once or twice that he considered Samwise to be the true hero of his saga, and by Tolkien's standards, he certainly was. Recall Tolkien's words about the men who inspired the character - Tolkien considered these men to be "so far superior to [him]self". There are other heroes in the story - Aragorn, Legolas, Gimli, Frodo, Faramir, Eomer, Eowyn, Merry, Pippin, Gamdalf, Treebeard... But none of these characters are as unassuming and humble as Samwise Gamgee. None of these characters thinks as little of themselves, or doubts themselves, or unjustly criticizes themselves, as much as Sam does, but none of them show such resilience and courage in the face of adversity as does Samwise. No one underestimates himself as much as Sam, and as we all know, Sam's extremely unfavorable assessment of his own abilities and virtues are completely unfounded. He is the ideal hero, because he doesn't think he has heroism in him.
Tolkien spoke of this on occasion, as noted above:
I think the simple 'rustic' love of Sam and his Rosie (nowhere elaborated) is absolutely essential to the study of his (the chief hero's) character, and to the theme of the relation of ordinary life (breathing, eating, working, begetting) and quests, sacrifice, causes, and the 'longing for Elves', and sheer beauty.
And:
I can only say, for your comfort I hope, that the 'Sam Gamgee' of my story is a most heroic character, now widely beloved by many readers, even though his origins are rustic.