The fallacy of four terms occurs when a categorical syllogism fails to establish a connection between the first and the last category via some middle category. This is usually because of a shift between two superficially similar categories that are really not the same.
Here is an example:

1. Sharp knives can hurt.
2. Hurtful things are always wrong.
3. Therefore, sharp knives are always wrong.
The problem here is that "things that can hurt" and "hurtful things" are not identical terms, and they do not mean the same thing. So the argument does not really show us a category that links "sharp knives" with "things that are always wrong."
Sometimes when this fallacy is committed, an identical word or phrase is used twice, masquerading as a middle category, but with a switch in meaning (which is called "equivocation"). This acts a disguise of there being an additional term introduced.
Here is an example of that:

1. Starbucks charging me $10 for a latte is highway robbery!
2. Highway robbery is deserving of five years in prison.
3. Therefore, Starbucks should go to prison for five years.
Here there are four terms, cloaked by equivocation between B and C:
A = Starbucks charging $10 for a latte
B = metaphorical highway robbery
C = literal highway robbery
D = deserving of five years in prison
1. All A's are B
2. All C's are D
3. All A's are D
When equivocation is used to mask the extra term, the fallacy is sometimes called "ambiguous middle."