Farhan Qureshi (R. Madhavan), Raju Rastogi (Sharman Joshi), and Rancho or Rancchoddas Shyamaldas Chanchad (Aamir Khan) are three engineering students who share a room in a hostel at the fictional ICE, one of the best colleges in India (modeled after IIT).
Their story is framed as a flashback from the present day, ten years after graduation. Having lost contact with Rancho who disappeared during the graduation party, Raju and Farhan begin a journey to find him. They are joined by Chatur, now a wealthy and successful businessman, who joins them to settle a bet with Rancho after Rancho had changed his Teacher's day speech which was embarrassing. Chatur also wants to meet a scientist named Phunsukh Wangdu with whom he has to sign a deal. From Chatur they also come to know that Rancho is in Shimla.
While Farhan and Raju are mediocre students from modest backgrounds, Rancho is a wealthy genius who studies for the sheer joy of it. Yet it is precisely his passion for knowledge and his gift for creating machines that incurs the wrath of Professor Viru Sahastrabudhhe (ViruS) (Boman Irani). Threatened by Rancho's talent, ViruS labels him an "idiot" and attempts on a number of occasions to destroy his friendship with Farhan and Raju. In contrast, ViruS’ model student is Chatur Ramalingam or "Silencer," (Omi Vaidya) a geek who lives by conforming to the expectations of the system, mindless cramming, and unethical means of destroying his competition. Meanwhile, Rancho also falls in love with ViruS' pre-med daughter Pia (Kareena Kapoor) when he and his "buddies" (Raju and Farhan) "crash" her sister's wedding. He advises Pia not to marry her fiance because her fiance is too money minded. Pia later in front of Rancho breaks her engagement and falls in love with Rancho. In between Pia and Rancho's love story, Rancho saves Raju's father from dying just a day before Rancho's exams. The next day, all the three friends write their examination. But when the results are out, Raju and Farhan are shocked. Not because they secured the lowest marks. But because Rancho stood first. Even ViruS and Chatur are shocked. A few days later, ViruS places a bet with Rancho where ViruS will shave off his mustache if either Raju or Farhan get a job before graduation.
Cut to present, the three men reach Shimla but are shocked to find out that Rancho had taken someone else identity. The real Rancchoddas was poor in studies and his father, a wealthy man had sent his gardener's son to school and college with his son's name so that his son could get a degree in return. The real Rancchoddas then gives the address of Rancho who now lives in Leh, Ladakh.
Back to the past, Rancho in a drunk state confesses his love to Pia. But Farhan and Raju, urinate on the door of ViruS's house. They escape but ViruS does see Raju. The next day he threatens Raju that either he leaves the college or stands witness against Rancho. Raju unable to bear with either of the situation offered to him tries to commit suicide by jumping from ViruS's office. He survives but is nearly paralyzed. He recovers with Rancho's efforts and even gets a job. There, Farhan tells his father that he wants to become a wildlife photographer and his father finally agrees. ViruS who is now without his mustache, seeks revenge by setting a tough paper. Pia gives the duplicate keys to Rancho and he and Farhan steal the paper from ViruS's office. ViruS comes to know and throws them out of the college. Pia protests and tells ViruS that her brother (ViruS's son) had committed suicide because he couldn't take the pressure of examinations. Pia's elder sister who is pregnant goes into labor pain and Rancho with help of his friends and Pia who is in hospital deliver the baby on campus. ViruS forgives Rancho, Farhan and Raju.
Cut to present, Farhan and Raju convince Pia to leave her wedding function and come along with them to meet Rancho. They do finally meet Rancho who now runs a science school in Leh. Chatur is very happy that he's finally beaten Rancho but is shocked to know that Rancho's real name is Phunsukh Wangdu, the scientist. The film ends with Pia and Phunsukh confessing their love for each other and Chatur asking for forgiveness.