An idiom is a common phrase which means something different from its literal meaning but can be understood because of their popular use.
Idioms are difficult for someone not good at speaking the language. Some idioms are only used by some groups of people or at certain times. The idiom shape up or ship out, which is like saying improve your behavior or leave if you don't, might be said by an employer or supervisor to an employee, but not to other people.
Idioms are not the same thing as slang. Idioms are made of normal words that have a special meaning known to almost everyone. Slang is usually special words, or special meanings of normal words that are known only to a particular group of people.
To learn a language a person needs to learn the words in that language, and how and when to use them. But people also need to learn idioms separately because certain words together or at certain times can have different meanings. In order to understand an idiom, one sometimes needs to know the culture from which the idiom comes.
To know the history of an idiom can be useful and interesting. For example, most native British English speakers know that "No room to swing a cat" means "there was not much space" and can use the idiom properly. However, few know this is because 200 years ago sailors were punished by being whipped with a "cat o' nine tails". A big space was cleared on the ship so that the person doing the whipping had room to swing the cat.
An idiom is a phrase whose meaning cannot be understood from the dictionary definitions of each word taken separately. The linguist's term for the real meaning of an idiom is the subtext.