Duncan Gregory's great great grandfather was James Gregory and he was the youngest son of another James Gregory (1753-1821) who was professor of medicine at Edinburgh University. His mother was Isabella McLeod and she was left to bring up the family after Duncan's father died when he was seven years old.

Duncan was educated by his mother until he was ten years old then, after this, by a private tutor. His liking for constructing mechanical devices was noticed at this early age. In October 1824 he entered Edinburgh Academy (where Maxwell and D'Arcy Thompson were to be educated). He showed great promise at school and, during the winter of 1827, Gregory was sent to an academy in Geneva where his mathematical talents were obvious to the teachers. On his return from Geneva, Gregory became an undergraduate at Edinburgh University where he began to study advanced mathematical topics and he also conducted experiments with polarised light. He was most influenced by William Wallace who held the chair of mathematics at Edinburgh University.

In October 1833, at the age of 20, Gregory entered Trinity College, Cambridge, receiving his B.A. in 1837, being ranked fifth wrangler, and his M.A. in 1841. However his interests were not only in mathematics for at Cambridge he continued to pursue his interest in chemistry which he had shown while an undergraduate at Edinburgh University. He was one of the founder members of the Cambridge Chemical Society but had broader interests than even mathematics and chemistry for he also studied physics, astronomy and botany. In October 1840 he became a Fellow of Trinity and also an assistant tutor at the College, devoting himself entirely to mathematics from this time on. At this time the Cambridge Mathematical Journal was beginning publication and Gregory became its first editor. Many of the papers in the early parts of the Journal are written by Gregory himself. Gregory declined a chair in Toronto in 1841 due to ill health. He returned to Edinburgh, where he was an unsuccessful applicant for a chair, but he died there shortly afterwards in his father's house, Canaan Lodge, at the age of 30.

His main contribution was his theory of algebra which he defined as the study of the combinations defined by the laws of operation to which they were subject. This is one of the first definitions of modern algebra. His work in this area is described in the paper On the real nature of symbolic algebra which Gregory published in the Transactions of the Royal Society of Edinburgh. In this work Gregory built on the foundations of Peacock but went far further towards modern algebra. Gregory, in his turn, had a major influence on Boole and it was through his influence that Boole set out on his innovative research.

Two other important works by Duncan Gregory are Examples of the Processes of the Differential and Integral Calculus and A Treatise on the Application of Analysis to Solid Geometry. The first became an important text at Cambridge which, by this time, had accepted Peacock, Herschel and Babbage's Analytical Society reforms, and continental methods of calculus were being taught in Cambridge. The second work was unfinished at his death but completed and published the following year.

On the whole, his work reveals a vast acquaintance with continental mathematics, and is often enlivened with historical remarks. The quality of his mathematical advances was indeed unusual for one who never held a senior position in the university. Of an amiable disposition and an active disinterested kindness, he unfailingly shared with others the extent and variety of his information, and his experience as an editor.