Older Ted – "Well, kids, here we are. We've arrived. My 30th birthday. The long-awaited story of the goat. That week started just like any other. Barney woke up in some girl's bed." Barney actually wakes up in Robin's bed. Barney and Lily talk about what happened and decide that they will not speak about what happened. Barney is concerned that he slept with his best friend's (Ted's) ex-girlfriend and he broke a code. Older Ted – "But pretending it never happened wouldn't be that easy." Everyone at the table is talking about "hitting it", but they don't tell Barney what they are talking about until Barney is about to have a heart attack from the conversation that he thinks is about having sex with Robin. Ted tells them that he is getting rid of things, but he is having a hard time not talking about having sex with Robin. Robin and Barney walk away from the table and talk, but Ted comes up to them and tells him that he knows what they are up to, which makes Barney freak out even more. Marshall is at the apartment and Barney calls him and asks him to be his lawyer. Marshall shows up at Barney's office and Barney wants to tell Marshall a secret, but Marshall refuses to be told. Barney eventually gets him to listen and tells him that he slept with Robin. Barney reminds Marshall that he can't tell anyone since it is attorney-client privilege.
Marshall freaks out and tells Barney that he at least has to tell Lily, but Barney tells him that he can't. Barney wants Marshall to make sure that he didn't break "The Bro Code." Older Ted – "For many years, we had heard Barney quote the Bro Code. A list of dos and don'ts for all bros. Some were basic. Some were unbelievably complicated. And some were just plain disturbing. Marshall tells him that it is not a legal document, it is just something that Barney wrote, but Barney tells Marshall that he didn't write it and tells Marshall about the history of the Bro Code. In 1776 in Philadelphia, when Benjamin Franklin and George Washington sit down and discuss that there should be a group of rules regulating their friendship. Barnabas Stinson volunteers to write the Bro Code on the back of the Constitution. Barney tells Marshall that he feels bad that the Bro Code states that you can't sleep your bro's ex and he wants Marshall to find a loophole. Marshall tells him that he doesn't want to do it, but Barney insists that he does it. Older Ted – "While Marshall examined the Bro Code, Lily's kindergarten class welcomed a special guest." The special guest is a goat and Farmer Frank tells the kids that when he picks up the goat after a few days, he will bring it took a butcher shop. Older Ted – "And Frank went on to traumatize Lily' entire class with a graphic explanation of where meat comes from." The kids don't want the goat, Missy, to be eaten, so Lily puts Missy in the back of a cab and brings her back to the apartment. Lily tells Ted that the animal rescue will pick her up on Monday, but Ted isn't thrilled about the idea. Older Ted – "And, boy, was I right, because what Missy the goat would go on to do in that bathroom was so…No, you know what? I'm getting ahead of myself. We'll get there." Robin shows up at the apartment and asks why the goat turd is on the floor. Marshall shows up and acts guilty and Robin talks to Marshall in the kitchen and tells him not to say anything. At work, Marshall tells Barney that there is no loophole in the Bro Code. Barney thinks that maybe Ted has already broken the Bro Code, but Marshall explains that Ted has followed everything perfectly and gives him several examples. Barney is upset and tells Marshall to find the loophole. Marshall tells Barney that he has to tell Ted. Older Ted – "Which brings up to April 25, 2008. My 30th birthday. Or as it would come to be referred to in later years, the Day of the Goat." Lily calls Barney and tells him that he has to come to up to the party to see the goat wearing a party hat. Older Ted – "In a few short hours, Lily would come to regret those words. But we'll get there." Barney gets off of the phone when Ted gets in the limo with Barney to go to the apartment. Barney takes Ted to Vegas.
Barney tells Ted that there is a roof-top party, but he doesn't want Ted to go and has a whole plan for Vegas. Barney tells Ted that he has to tell him something and Ted guesses that he slept with Robin. Ted tells Barney how he figured it out and it was after Robin talked to Marshall about being quiet. Robin blurts out that she slept with Barney and tries to explain the situation. Ted tells her that he isn't mad and Barney is impressed that he isn't mad. Ted explains that he is dating someone else anyway and that his mother is coming in to town and tells him that he should sleep with his mother. At the party, Lily wants to keep the goat, but Robin tells them that in the morning, they will not want to keep the thing. Lily tells Robin that she knows that her and Barney slept together and she asks if it was amazing and she was curious. Ted continues to yell at Barney about sleeping with Robin and he asks Barney to tell him how it happened. They start fighting and he tells Ted that he can hit him. Ted punches Barney in the groin. Barney asks if they are over the Robin thing, but Ted explains that he thought that Barney wouldn't do something bad to him. Ted tells Barney that he started to put things in a box that he didn't need anymore and maybe Barney belongs in the box. Barney wants to stop the conversation, but Ted gets out of the limo and goes to the apartment. Barney is left in the limo and Ted goes to the party and everyone surprises him.
Older Ted – "Oh, right, the goat. It's so funny, you're going to love this. So later that night, the goat locked herself in the bathroom and was eating on of Robin's washcloths and… Wait, hold on, Robin wasn't living here on my 30th birthday. When did this happen? Oh, wait, the goat was there on my 31st birthday. Sorry, I totally got that wrong."