Voldemort, thinking Snape is the master of the Elder Wand because he killed Dumbledore, kills Snape. While viewing Snape's memories, Harry comes across the stunning realization that Harry himself is an unintended Horcrux and that he must die for Voldemort to die. Voldemort "kills" Harry, but he only destroyed the Horcrux in Harry. Harry and Voldemort have a fight, during which Neville kills Nagini, also a Horcrux. Harry uses Malfoy's wand in the duel against Voldemort, and since Malfoy is the true master of the Elder Wand (he disarmed Dumbledore before he was killed by Snape), Harry is now the Elder Wand's master. When Voldermort tries to kill Harry with the Elder Wand, it backfires and kills Voldemort. Harry snaps the Elder Wand in two. We then cut to nineteen years later where an adult Harry and Ginny, along with Ron and Hermione, are sending their kids off to Hogwarts.