This is a textbook on the history, philosophy and foundations of mathematics. One of its aims is to present some interesting mathematics, not normally taught in other courses, in a historical and philosophical setting. The book is intended mainly for undergraduate mathematics students, but also for students in the sciences, humanities and education with a strong interest in mathematics. It proceeds in historical order from about 1800 BC to 1800 AD and then presents some selected topics of foundational interest from the 19th and 20th centuries. Among other material in the first part, the authors discuss the renaissance method for solving cubic and quartic equations and give rigorous elementary proofs that certain geometrical problems posed by the ancient Greeks (e.g. the problem of trisecting an arbitrary angle) cannot be solved by ruler and compass constructions. Among the topics in the second part, they sketch a proof of Gödel's incompleteness theorem and discuss some of its implications, and also present the elements of category theory. The authors' approach to most of these matters is new.