The Magician's Code - Part Two

HIMYM episode 7x24 (160)

Barney TheMagiciansCode
First aired:
May 14, 2012
Pamela Fryman
Craig Thomas
Carter Bays
Barney's Blog
Barney's Blog 2

Images (0)

On Barney's future wedding day, his wife is finally revealed, and the gang reminisces about the time they encouraged Ted to follow his heart and go after the one that got away.


After the birth of Lily and Marshall's baby, Ted talks to Robin about how he wants a family. She encourages him to go after the one who got away, Victoria, saying that he consistently sabotages himself by choosing women he knows he has no future with and that she was the only girl he ever dated with the potential to be "The One." He gives her a call and invites her to MacLaren's and arranges to meet at 1:30 P.M. When she arrives, she is in a wedding dress. Victoria tells him that today is her wedding with Klaus, but she has always had Ted in the back of her mind. If he wants to drive off into the sunset with her, now is their chance. After deliberating with the gang, he takes her into the car, seemingly to drive off into the sunset with her. However, he tells her "I was left at the altar and it almost killed me. You're someone's fiancée, and I have to respect that," and says he's going to drive her back to the church. Once he gets near the church, he sees flashbacks of Victoria, and drives past the church, where Ted and Victoria hold hands and do indeed drive off into the sunset.

Meanwhile, Quinn and Barney plan a romantic getaway to Hawaii. However, in Barney's suitcase is a box which he refuses to open, due to "The Magician's Code." "The Magician's Code" is a code taught to Barney by his former magic teacher who said "A Magician should never reveal his greatest tricks." Barney and Quinn get held up by security. As a security guard questions Quinn, he asks her what is her occupation - to which she says she is unemployed. She says she wanted to surprise Barney when they were on their vacation, saying she quit stripping just for him. Afterwards, Quinn is told she can leave but Barney must stay, but Barney tells her to wait and that he will finally reveal the magic trick. After an elaborate magic ploy, it is revealed that in the box was an engagement ring, which he uses to propose to Quinn. She accepts. They run off to tell the gang, and Barney and Robin are left in the room alone. He apologizes if this may be kind of weird for her, but she says she's happy for them. Then there is a flash forward to Barney's wedding day, and when Ted walks into the bride's room, it is finally revealed to be Robin.


  • Barney's love of magic tricks is a recurring element throughout the show.
  • In Ducky Tie​, Victoria mentioned that she is getting engaged to Klaus.
  • Robin mentions Stella and Zoey, two of Ted's ex-girlfriends.
  • In one of the flashback scenes, Marshall's Fiero is seen, and the song I'm Gonna Be (500 Miles) by The Proclaimers is being played in it. These elements were established in Arrivederci, Fiero​.
  • Stella left Ted at the altar in Shelter Island​.
  • Making a sign as a result of something someone did was first referenced in Disaster Averted.
  • During the flashback of Marshall stapling himself, Ted can be seen eating a sandwich. "Eating a sandwich" is Ted's way of telling his kids that they were smoking marijuana. The term "eating a sandwich" was first introduced in How I Met Everyone Else​.
  • When in the airport security room, Barney says "Man, I wind up in these rooms a lot". This is a reference to Sweet Taste of Liberty​, where he and Ted also get questioned by security at the airport (and where Barney similarly refuses to change his story).
  • Robin references Ted's original break-up with Victoria, which occurred in Nothing Good Happens After 2 A.M..
  • By this episode, when the pair getting married is finalized, it had already been two full seasons (all of Seasons 6 and 7) since the wedding is introduced. It will be another two seasons before it occurs.
  • Don in Twin Beds also thinks that Ted is gay.

Future References (Contains Spoilers)


For a listing of all images on the wiki tagged as being from this episode, see Category:The Magician's Code - Part Two images.

Memorable Quotes

Mr Flanagan: The Magician's Code forbids me from telling you anything more about the trick.
Loretta: Hey, come back to bed!
Mr Flanagan: Okay, it involves a bed.
Young Barney: Can you at least tell me the name of this trick?
Mr Flanagan: Sure. It's called...
Barney: The disappearing salami.
Barney talking about the Magician's Code

Marshall: You're gonna love the park, buddy. It's a great place to meet chicks... or dudes... or both.
Lily: We love you, no matter what.
Marshall and Lily talking to Little Marvin.

Ted: Seeing them in there all together like that, they're a family, you know? That's what I want.
Robin: Oh, Ted, I'm glad we're friends again.
Ted: Me, too.
Robin: Because as your friend, I have to tell you: You're full of crap! You say you want a family, you say you want to meet "The One," but you are always chasing the wrong women.
Ted: That is not true.
Robin: Look at the women you date, starting with me: I told you right away I didn't want marriage or kids. Stella had a child with another man who she still loved. Zoey was married and trying to sabotage your career and wore a lot of stupid hats. If you really wanted a family, you would stop pursuing women you know that there is no future with.
Ted: Okay, first of all, hats were in that year, kind of. Secondly, I don't always choose women there's no future with, kind of.
Robin: Name one exception.
Ted: Victoria. Victoria was great.
Robin: Exactly. And you threw it all away to chase after some hot piece of ass.
Ted: You mean you?
Robin: Thank you.

Ted: I'm taking you back.
Victoria: I don't understand. I thought you wanted this.
Ted: I do want this. I've thought about you so many times. What might have been. But I got left at the altar, and it nearly killed me. You're someone's fiancé, and I have to respect that. So let's hit a motel, jam in a quickie, and get you back to your wedding (both giggle). It's the right thing to do.

Lily: Oh Marvin, you´re about to hear you first love story.
Quinn: Once upon a time this creepy magic dude was boning Barney's mom....

Notes and Trivia

Goofs and Errors

  • In the photos sequence, Marshall doesn't have his eyes closed, as seen in Say Cheese​.
  • Robin is seen quite frightened at the hospital, and even faints when Lily is about to deliver the baby, but in The Front Porch​, she has already helped a guest (on her show), deliver a kid. However as Ted says "it's different when it's someone you love." Because of the close relationship Robin and Lily share it is likely that delivering Lily's baby was much more emotionally draining than delivering a stranger's baby.

Allusions and Outside References

  • When Barney returns home, Quinn states that his bedroom was too "American Psycho".
  • When Barney begins the magic trick, he chants "sim sala bim," referencing the magician Harry August Jansen, who would utter the same words.


Other Notes

  • Along with The Magician's Code - Part One​, this marked the first time two episodes were aired on the same night as part of a season finale. The next time this would happen is in Season 9 when the series finale consisting of two episodes (Last Forever - Part One and Last Forever - Part Two) would be aired back-to-back.
  • Ed Alonzo, who plays Guard #2, is an actual magician, and creates all the magic tricks seen on the show.
  • Alongside The Magician's Code - Part One, it was the most watched event on CBS until September 7, 2012 when all the major American channels aired the Stand Up To Cancer telethon.
  • Rob Huebel (Mr. Flanigan) played a supporting role in the film I Love You, Man in which Jason Segel was a co-star.
  • Despite the episode taking place after Marvin's birth, which Alyson Hannigan's pregnancy coincided with, Hannigan was still seven months pregnant during production of this episode, which necessitated her wearing loose clothing and carrying the baby to conceal her still-expanding waistline.
    • Footage of Lily summoning Ted to the bride's room, from The Best Man, shot before Hannigan's pregnancy, was reused for the beginning of the episode, and Lily does not make an appearance for the final flashforward scene. This was done so that Lily would not appear pregnant in her bridesmaid scenes.



Featuring Craig Thomas, Chris Harris and Sue Federman.


  • This episode, along with The Magician's Code - Part One, was viewed by 8.49 million people. [1]
  • Donna Bowman of the AV Club gave the episode a B, stating that much happened in the episode even if there were contradictions along the way while the outcomes of certain events are attempts at misdirection. [2]
  • Entertainment Weekly's Michelle Profis stated the episode does not leave anything for the audience to contemplate before the next season but left some emotional moments such as the baby being named after Marshall's father. [3]
  • Ethan Alter of Television Without Pity gave the episode a C-. [4]
  • Robert Canning of IGN gave the episode 8 out of 10. [5]
  • The St. Petersburg Comic Review gave this episode 9.5 out of 10 stars. "...Barney with the magic again."


External Links

Previous episode
The Magician's Code - Part One
The Magician's Code - Part Two
(all episodes)
Next episode →
Community content is available under CC-BY-SA unless otherwise noted.