dans vs d'en
Summary
dans is a preposition meaning "in/inside/within" (dans la boîte; dans deux jours = "in two days' time"); d'en is de + the pronoun en elided (il vient d'en parler = "he just talked about it"; je suis content d'en avoir = "I'm glad to have some"). Test: dans is always followed by a noun phrase; d'en is always followed by a verb (usually an infinitive) or an adverb. Also covers d'en face / d'en haut ("from the one opposite/above").
Explanation
Dans and d'en are pronounced alike in fluent speech, but they belong to different structures entirely. Dans is a simple preposition meaning "in," "inside," or "within": dans la boîte ("in the box"), dans la voiture ("in the car"). With time expressions, dans means "in [an amount of time] from now": dans deux jours ("in two days' time"), dans une heure ("in an hour").
D'en is not one word but two: the preposition de plus the pronoun en, elided to d' before the vowel. En here stands in for a previously mentioned thing introduced by de, du, de la, or des: il vient d'en parler ("he just talked about it," where en replaces de ce sujet); je suis content d'en avoir ("I'm glad to have some," where en replaces des/du + noun).
The structural test is the most reliable: look at what follows the word. Dans is always followed by a noun phrase (an article + noun, or a time expression): dans le jardin, dans trois semaines. D'en is always followed by a verb — most often an infinitive — or occasionally an adverb: d'en parler, d'en avoir, d'en face, d'en haut. If a noun comes right after, it's dans; if a verb or adverb comes right after, it's d'en.
A second check works for the pronoun: try replacing the word after d' with the full phrase en is standing in for. Il vient d'en parler → il vient de parler de ce sujet confirms that en is a pronoun referring back to something, which only happens with d'en, never with dans.
Two fixed expressions deserve special mention: d'en face ("from the one across the way / opposite") and d'en haut ("from above / from upstairs"), as in le bruit vient d'en haut ("the noise is coming from upstairs"). Both follow the same pattern — de + en, elided — and are both followed by what is really an adverb of place standing in for a longer phrase (d'en haut = de la partie qui est en haut).
In short: dans is a preposition placed before a noun phrase ("in/inside"); d'en is de + en placed before a verb or adverb, with en replacing something already mentioned. Check what comes next — a noun means dans, a verb or adverb means d'en.
Examples
Les clés sont dans le tiroir. — The keys are in the drawer. (dans: preposition followed by the noun phrase le tiroir.)
Il vient d'en parler avec elle. — He just talked about it with her. (d'en: de + pronoun en, followed by the infinitive parler.)
Dans deux jours, je serai content d'en avoir fini. — In two days, I'll be glad to have finished it. (dans (before the time expression deux jours) vs d'en (before the infinitive avoir).)
Le bruit vient d'en haut, pas d'en bas. — The noise is coming from above, not from below. (d'en haut / d'en bas are fixed adverbial expressions (de + en). There is no *de dans in French — 'inside the cellar' is simply dans la cave.)
Elle habite dans l'immeuble d'en face. — She lives in the building across the way. (dans before the noun immeuble; d'en face as a fixed adjectival phrase.)
Common mistakes
Il vient d'en deux minutes.
Il vient dans deux minutes.
dans is the preposition used before a time expression ("in two minutes"); d'en (de + the pronoun en) can only be followed by a verb or an adverb, never directly by a noun phrase like deux minutes.
Prerequisites
Related rules
homophonesspellingprepositionspronoun-en