After burying Dobby, Harry Potter asks the goblin Griphook to help him, Ron, and Hermione break into Bellatrix Lestrange's vault at Gringotts bank, suspecting a Horcrux may be there. Griphook agrees, in exchange for the Sword of Gryffindor. Wandmaker Ollivander tells Harry that two wands taken from Malfoy Manor belonged to Bellatrix and to Draco Malfoy, but Malfoy's has changed its allegiance to Harry.
In Bellatrix's vault, Harry discovers the Horcrux is Helga Hufflepuff's cup. He retrieves it, but Griphook snatches the sword and abandons the trio, leaving them cornered by security. The three release the dragon guardian and flee on its back. Harry sees a vision of Voldemort killing goblins, including Griphook, and learns Voldemort is aware of the theft. Harry also realises there is a Horcrux at Hogwarts somehow connected to Rowena Ravenclaw. The trio apparate into Hogsmeade, where Aberforth Dumbledore reluctantly instructs the portrait of his deceased younger sister, Ariana, to fetch Neville Longbottom, who leads the trio through a secret passageway into Hogwarts.
Severus Snape hears of Harry's return and warns staff and students of punishment for aiding Harry. Harry confronts Snape, who flees after Minerva McGonagall challenges him to a duel. McGonagall gathers the Hogwarts community for battle. At Luna Lovegood's insistence, Harry speaks to Helena Ravenclaw's ghost, who reveals that Voldemort performed "dark magic" on her mother's diadem, which is in the Room of Requirement. In the Chamber of Secrets, Ron and Hermione destroy the Horcrux cup with a Basilisk fang. In the Room of Requirement, Draco, Blaise Zabini and Gregory Goyle attack Harry after he finds the diadem, but Ron and Hermione intervene. Goyle casts a Fiendfyre curse and, unable to control it, is swallowed up by the flames while Harry and his friends save Malfoy and Zabini. Harry stabs the diadem with the Basilisk fang and Ron kicks it into the Room of Requirement, where it is destroyed. As Voldemort's army attacks, Harry, seeing into Voldemort's mind, realises that Voldemort's snake Nagini is the final Horcrux. After entering the boathouse, the trio witness Voldemort incorrectly telling Snape that the Elder Wand cannot serve Voldemort until Snape dies since he killed its last owner (Dumbledore); he then orders Nagini to kill Snape, which Nagini does. Before dying, Snape tells Harry to take his memories to the Pensieve. In the chaos at Hogwarts, Fred, Lupin, and Tonks have been killed.
Harry learns from Snape's memories that Snape loved Harry's late mother, Lily, but despised his father, James, who had bullied him. Following her death, Snape worked secretly with Dumbledore to protect Harry from Voldemort because of his love for Lily. Harry also learns Dumbledore wanted Snape to kill him, and that the Patronus doe he saw in the woods that led him to the sword had been conjured by Snape. Harry discovers that he himself became a Horcrux when Voldemort originally failed to kill him and that Harry must die to destroy the piece of Voldemort's soul within him. Harry then surrenders himself to Voldemort in the Forbidden Forest. Voldemort casts the Killing Curse upon Harry, who finds himself in limbo, where Dumbledore's spirit meets him and explains that the part of Voldemort within Harry was killed by Voldemort's own curse. Harry then returns to his body, determined to defeat Voldemort once and for all.
Voldemort announces Harry's apparent death to everyone at Hogwarts and demands they all surrender. As Neville gives a defiant response and draws the Sword of Gryffindor from the Sorting Hat, Harry reveals he is still alive. While Harry confronts Voldemort in a duel throughout the castle, Molly Weasley kills Bellatrix in the Great Hall, and Neville decapitates Nagini, leaving Voldemort mortal. Harry and Voldemort's fight ends with Voldemort's own Killing Curse rebounding, killing and obliterating him. After the battle, Harry explains to Ron and Hermione that the Elder Wand had recognised him as its true master because he had disarmed Draco, who earlier had disarmed its previous owner, Dumbledore, but instead of claiming the Elder Wand, Harry breaks and discards it.
Nineteen years later, Harry, Ginny, Hermione, Ron, and Draco proudly watch their own children leave for Hogwarts at King's Cross station.
When did Harry become a Horcrux?
When Voldemort originally failed to kill him