According to the Merriam –Webster Dictionary, irony is using words that mean the opposite of what is intended in order to generate humor. It may also refer to a situation where the results are the opposite of what is expected. For example, saying “that was fast” when someone was several hours late doing a task is an example of using irony.
When it comes to situations, irony refers to incongruity in situations. If someone is afraid of flying due to the belief that the plane is likely to crash and they instead take a train and crash in that vehicle instead, this is an example of irony. The person takes a train specifically to avoid planes, and it turns out that the vehicle they thought of as a safe alternative is the more dangerous one. This is the opposite of their expectations.
In literature and plays, dramatic irony is when the audience knows something that the characters in the story do not. An example is when the true identity of a killer is revealed in a murder story, but the other characters have yet to figure it out for themselves. The incongruity between what the audience knows and what the character knows is where the irony comes from.