There are three separate issues.
L' is always short for le and d' is always short for de. Les and des are never elided. The same goes for je, me, ne, se, te.
The elided form (d', l', …) is used when the next word starts with a vowel sound: le fils, l'enfant. Semi-vowels count as vowels: l'iode, l'oiseau. The letter H is special: although it is never actually pronounced, it counts as a consonant in some words (aspirated H), while it doesn't count in other words (silent H). The general rule is that words derived from Latin or Greek roots have a slient H while words built on Germanic and other roots have an aspirated H (there are exceptions).
This covers the easy part. The third and more difficult issue is that there are multiple words spelled de.
- A preposition: “le livre de ma sœur” (lit. “the book of my sister”, i.e. my sister's book); “il sort de la maison” (“he comes out of the house”).
**De le* is contracted to du and **De les* is contracted to des.
- The first part of the partitive article: “il boit de la bière” (“he drinks (some) beer”). Here de la is the partitive article; the fact that it looks like de followed by the definite article is a coincidence.
Again, **de le* is contracted to du and **De les* is contracted to des.
- The plural indefinite article; this is normally des but sometimes de.
Especially on that last topic, see also Usage of "de" at the beginning of a sentence and When to use du instead of des?