One of my friend told me to break my legs before entering the examination hall...I was confused with her words! How am I supposed to sit for the exam if i broke my legs? Or maybe is it kind of idioms/phrases?
The usage of the phrase "break a leg" originates from within the theatrical profession. It was considered that to wish an actor "good luck" for a performance was to "jinx" them and have the opposite effect. As a result it was wished they would "break a leg" and thus cause "good luck".
This is referenced in the movie the Producers where you can hear it used in this song.
The confusion caused by those who do not know this convention is illustrated here:
So you are not alone in your reaction to this!
I could not find any support for the claim that "break a leg" was once slang for bowing. Presumably it was never particularly widespread. Therefore, and since the phrase seems to be relatively recent, I doubt the theory (on the English Wikipedia) that this is how it arose.
As a native German speaker I find one explanation in the Wikipedia article particularly convincing. (The version at the German Wikipedia seems a bit clearer to me.) It passes through the equally enigmatic German phrase "Hals- und Beinbruch".
It appears that there is a Hebrew expression "hazlacha uwracha" ("הצלחה וברכה"), which turned into Yiddish "hatslokhe un brokhe", meaning "success and blessing". (Apparently the initial u of uwracha was reinterpreted as un, which is German und / English and.) There was a well known connection between German showpeople and the Rotwelsch language, which in turn had a strong Yiddish influence. It is therefore a totally plausible speculation that German showpeople unfamiliar with Hebrew turned the Yiddish phrase into the malapropism "Halsloch und Bruch" ("neck hole and fracture"), which was then replaced by "Hals- und Beinbruch" ("neck and bone fracture" or "neck and leg fracture"), already a frequently used phrase originally referring to actual accidents. (Compare "pots and pans" as a general reference to household goods.)
"Hals- und Beinbruch" first occurs in this new sense in the Google Books corpus in the 1860s. Today the phrase is still employed very commonly when wishing someone success (e.g. in a theatre show, in an exam, or sometimes in business talks - basically anything that resembles a performance), but has almost fallen out of use in its original sense.
Regardless of these details, it appears to be well established and generally accepted that "Hals- und Beinbruch" originates in the Yiddish (and ultimately Hebrew) phrase.
It seems plausible that this phrase crossed the Channel as part of the lively exchange of artists and showpeople between Germany and Britain, with Germans first wishing their English colleagues "leg fracture!" (edited: or "neck and leg break!" - see AlanCarmick's find in a slang dictionary) and then, when this wasn't understood, "break a leg!". "Break a leg" in this sense was first attested around 1920.
The other answers seem to define the phrase as "Good luck" but I would classify it a little more specifically as "Have a good performance".
The reason, as noted in the other answers, is commonly associated with theatrics, but the phrase is typically used when someone is about to "actually do something of significance" (hence the performance part).
You wouldn't, for counter-example, wish someone to 'break a leg' when buying a lottery ticket - even though you might wish them luck.
Italian provides a very different expression but with the same sense of threat and well wishing: "in bocco al lupo" - literally "in the wolf's mouth". See this entry on Italian Stack Exchange where the accepted answer notes the correspondence with the English "break a leg"
In Shakespearean times, if the audience liked a particular actor's performance, they would receive sustained applause at the end the performance, during curtain calls. Actors would place one foot in front of them and bend their back leg when taking a bow, thus 'breaking' a leg. It isn't used as an ill-wish, but as a friendly way to say, have a great performance and hope you receive many 'extra bows' to the audience at the end of the show.
I always enjoy seeing derivations of phrases when they force some idea to suit the needed outcome. One perennial is tips as T.I.P.S. and also "A camel passing through the eye of a needle".
I could not respond before Adam but yes, a leg is the vertical block on each side of the stage. To break it is to allow oneself to be seen behind it, being where one should not be. This can be easy to do since you cannot look out to the audience to see where the sight lines are without being seen yourself. The lines of sight are not marked on the floor so you need more experience than caution to stay clear of them. Being seen on the side of the stage takes focus from those on the stage and ruins the moment they are working on.
The wish that you "break a leg" is part of the actor's expressions of reverse luck. Wishing someone "luck" is a performer's death sentence requiring several steps to dispel. Wishing that they make a big mistake as in "Break a leg" is the standard warm hearted threat that lets them know you care.
I couldn't find an answer here that defined what a leg actually was. In theatrics, a "leg" is one of the curtains on the side of the stage that prevents you from seeing backstage. Also, "break" is a less common term for crossing in front of something. So to "break a leg" is to cross in front of the curtain, which means you're walking onto the stage.
As far as I know, the phrase "break a leg" originated as a phrase given before auditions. In essence, you are wishing that they will be cast into a part so they can make it on stage.
Break-A-Leg as a good luck wish for actors came into use during Vaudeville days. It was not uncommon for acts to not show up or be unable to perform. The director of the theater would book extra acts as "stand-by's". These acts would not be paid unless they would appear on stage by breaking the sight-line of the side curtains, known as "Legs". Hence "Break A leg" is the good luck wish to appear on stage and get paid for your peformance.