He was born on 22 October 1843 at Auchencairn near Kirkcudbright the son of John Mackay and his wife Jessie Sturgeon.
Although dallying with the idea of training as a minister he instead continued in mathematics, moving as a teacher to Edinburgh Academy in 1866.
He initially rented rooms but by 1880 he was living at 85 Great King Street, a grand property in Edinburgh’s Second New Town.
His proposers were Peter Guthrie Tait, George Chrystal, Fleeming Jenkin and Alexander Dickson.
In 1923 his brother Robert Mackay donated 52 ancient mathematical books previously owned by John to St Andrews University.