An idiom is a phrase with a figurative meaning that can’t be understood just knowing the meaning of the words inside the phrase.
Wikipedia states there are 25,000 idioms in English. I think that’s a lowball number and doesn’t count regional dialect, youth slang, and “shop talk” from various professions.
A few example idioms cited by Wikipedia are “pulling my leg” which means you are joking with me and “keep an eye out” which means in a general sense to warn someone of something.
We need idioms because they were coined to communicate a specific and usually quite precise meaning for which there is no exact word. The clever or creative ones tend to be memorable, and what’s memorable gets repeated in meme-like fashion. Idioms are a type of figurative language that plugs the gaps in our vocabulary. Sometimes they’re a more casual way to talk about an idea, but usually they add concise precision that alternative wording doesn’t have. Sometimes they’re the only expression for that exact idea.
Idioms can be used to deliberately exclude people from conversations who speak the language well, but not natively, or they can be used to manipulate or make fun of the non-native speaker. (Don’t feel paranoid, English learners. I don’t think it’s common, but it’s absolutely possible in English and of course, in your native language as well.)