Origins
The prefix 'ex-' is a Latin-derived morpheme with one of the oldest PIE pedigrees in the English word-stock. It descends from Latin 'ex' (out of, from), itself from Proto-Indo-European *h₁eǵʰs or *eǵʰs, meaning 'out.' The same root gave Greek 'ex' or 'ek' (ἐξ, ἐκ — ex- before vowels, ek- before consonants), Old Church Slavonic 'iz,' Lithuanian 'iš,' and traces across other Indo-European branches.
In Latin, 'ex-' was productive on verbs with several interrelated senses: (1) motion out of, as in 'exire' (to go out — whence 'exit'), 'exportare' (to carry out — whence 'export'), 'expellere' (to drive out — whence 'expel'); (2) completeness or thoroughness, as in 'excitare' (to rouse completely — whence 'excite'), 'exhaurire' (to drain completely — whence 'exhaust'); (3) reversal or undoing, as in 'excusare' (to release from blame — whence 'excuse'); and (4) source or origin, as in 'ex origine' (from the beginning).
The prefix shows elaborate allomorphy in Latin, inherited into English. Before 'f' it assimilates to 'ef-' ('effect,' 'efface,' 'effluent,' 'effort'). Before voiced consonants (b, d, g, j, l, m, n, r, v) it usually drops the 'x' and appears as 'e-' ('eject,' 'elapse,' 'emit,' 'erupt,' 'evade,' 'educate,' 'eliminate,' 'erode,' 'evict'). Before vowels and many other consonants it remains 'ex-' ('exit,' 'exact,' 'example,' 'exhaust,' 'extend,' 'extract'). English has inherited these Latin allomorphs intact, which is why 'emit,' 'eject,' and 'exit' all share the same prefix despite different surface forms.
Middle English
In Middle English (c. 1200–1500), 'ex-' arrived in hundreds of Latin and Anglo-Norman borrowings: 'example,' 'excellent,' 'except,' 'exchange,' 'excite,' 'exclude,' 'excuse,' 'execute,' 'exercise,' 'exhibit,' 'exile,' 'exist,' 'expand,' 'expect,' 'expel,' 'expense,' 'experience,' 'expert,' 'explain,' 'explode,' 'explore,' 'export,' 'express,' 'extend,' 'external,' 'extract,' 'extreme.' In most of these the prefix was not clearly separable to English speakers because both prefix and base entered together.
A particularly important semantic development occurred in Modern English. Around the early nineteenth century, 'ex-' began to be used as an independent element meaning 'former,' attached to titles and roles with a hyphen: 'ex-president,' 'ex-minister,' 'ex-champion.' The Oxford English Dictionary cites early examples of 'ex-' in this sense from the late 1700s, with it becoming common in the 1820s–1830s, especially in American political journalism. By the twentieth century this productive 'ex-' had become fully established in English and spread to personal relationships: 'ex-wife,' 'ex-husband,' 'ex-boyfriend,' 'ex-girlfriend.' The freestanding noun 'ex' (meaning a former romantic partner) is a twentieth-century informal derivative: 'my ex,' 'his ex.' This is one of the rare cases where a bound morpheme has become a freestanding word.
The older 'out of' sense remains fully productive in technical and scientific contexts. English continues to form new 'ex-' words regularly: 'excommunicate,' 'exfiltrate' (military, 1950s), 'extricate,' 'expropriate,' 'extradite' (1848, from French), 'exoplanet' (1990, astronomy). Many of these coinages are built on Greek 'ex-' rather than Latin, reflecting the parallel history of the two forms.
Proto-Indo-European Roots
Greek 'ex-' / 'ek-' (the cognate prefix) is also productive in English, especially in scientific vocabulary. 'Exodus' (from Greek 'ex-' + 'hodos,' way out), 'ecstasy' (from Greek 'ek-' + 'stasis,' standing outside), 'eccentric' (off-centre), 'eclipse' (from Greek 'ek-' + 'leipsis,' a leaving out), 'ectopic' (out-of-place), and 'exegesis' (leading out, interpretation) all contain this prefix. English treats Greek 'ex-' and Latin 'ex-' as more or less interchangeable, which is etymologically correct since they descend from the same PIE root.
The pronunciation of 'ex-' in English varies: /ɛks/ when the prefix is stressed or precedes a voiceless consonant ('excellent,' 'expect'), /ɪks/ when unstressed before voiceless consonants ('except,' 'exhibit'), and /ɛgz/ before vowels when voiced ('example,' 'exact,' 'exist,' 'exaggerate'). The voicing rule is a regular English phonological pattern, not inherited from Latin.
Representative 'ex-' words include (from Latin directly or via French): exact, exaggerate, example, excavate, exceed, excel, except, exchange, excite, exclaim, exclude, exclusive, excuse, execute, exercise, exhale, exhaust, exhibit, exile, exist, exit, expand, expect, expel, expense, experience, expert, expire, explain, explode, explore, export, expose, express, extend, extension, external, extinct, extract, extraordinary, extreme. Productive modern 'former' sense: ex-boss, ex-boyfriend, ex-champion, ex-colleague, ex-convict, ex-girlfriend, ex-husband, ex-lover, ex-minister, ex-partner, ex-president, ex-wife. Greek-derived: eccentric, eclipse, ecstasy, ectopic, exegesis, exodus, exotic.