It is enunciated in the chapter III of the first book of A Treatise of Human Nature, "Of Knowledge", where the eponymous David Hume examines the seven fundamental relations between ideas: (i) resemblance, (ii) identity, (iii) relation in time and place, (iv) proportion in quantity or number, (v) degrees in any quality, (vi) contrariety. (vii) causation.
Concerning (iv), he argues that our reasoning about proportion in quantity, as represented by geometry, can never achieve "perfect precision and exactness, since its principles are derived from sense-appearance. He contrasts this with reasoning about number or arithmetic, in which such a precision can be attained:
"Algebra and arithmetic [are] the only sciences, in which we can carry on a chain of reasoning to any degreee of intricacy, and yet preserve a perfect exactness and certainty. We are possessed of a precise standard, by which we can judge of the equality and proportion of numbers; and according as they correspond or not to that standard, we determine their relations, without any possibilty of error. When two numbers are so combined, as that the one has always an unit answering to every unit of the other, we pronounce them equal; and it is for want of such a standard of equality in [spatial] extension, that geometry can scarce be esteemed a perfect and infallible science. (I. III. I.)
Note Hume's use of the word number in the ancient sense, to mean a set or collection of things rather than than the modern notion of "positive integer". The ancient Greek notion of "number" (arithmos) is of a (finite) plurality composed of units. See Aristotle, Metaphysics, Book Delta 1020a14 and Euclid, Elements, Book VII, Definition 1 and 2. The contrast between the old and modern conception of number is discussed in great detail in a recent book by John Mayberry (''The Foundations of Mathematics in the Theory of Sets', Cambridge, 2000, available in part online at http://www.maths.bris.ac.uk/~majpm/list.html .)
The passage is well known due to its being mentioned by Frege , who quoted it in the Grundgesetze. Frege probably never read Hume: this and many other philosophical references were taken by Frege second hand from a book by Baumann, Die Lehren von Raum, Zeit und Mathematik (Berlin 1868).
The principle was taken up independently by Georg Cantor as a measure of the size or power of two different sets, including infinite sets. Hume, being an empiricist , would have been disinclined towards this later development, arguing that we cannot compare collections of infinite size:
"As to those who imagine that extension is divisible ad infinitum ... the least as well as greatest figures contain an infinite number of parts, and since infinite numbers, properly speaking, can neither be equal nor unequal with respect to each other, the equality or inequality of any portions of space can never depend on any proportion in the number of their parts. It is true ... that the inequality of an ell and a yard consists in the different numbers of the feet of which they are composed, and that of a foot and a yard in the number of inches. But as that quantity we call an inch in the one is supposed to be equal to what we call an inch in the other, and as it is impossible for the mind to find this inequality by proceeding in infinitum with those references to inferior quantities, it is evident that at last we must fix some standard of equality different from an enumeration of the parts." (I. II. iv.) "Objections answered"
See also (I. II. ii.) Of the infinite divisibility of space and time.
The principle become the foundation of modern neo-logicism. See, for example, Frege's Conception of Numbers as Objects (1983), by Crispin Wright, who argues that Frege's logicist project could be revived by removing Basic Law (V) from the formal system. Arithmetic is then derivable in second order logic from Hume's Principle.