mid-14c., "edge of a sea or lake;" late 14c., of a written or printed paper, "space between a block of text and the edge of a leaf or sheet;" from Old French margin and directly from Latin marginem (nominative margo) "edge, brink, border, margin," from PIE root *merg- "boundary, border."
The general sense of "bordering space, boundary space, rim or edge" is from late 14c. Meaning "comfort allowance, cushion, scope, range, provision for enlarged or extended action" is by 1851; margin of error is attested by 1889. Stock market sense of "sum deposited with a broker to cover risk of loss" is from 1848. Related: Margins.