The true master of the Elder Wand at the end of the series is Harry Potter. The wand's allegiance passes to whoever defeats or disarms its current owner.
Severus Snape killed Dumbledore but never defeated him, so the wand never truly belonged to Snape. Harry's willingness to sacrifice himself and his final defeat of Voldemort cement his mastery.