Fermat was born in Beaumont-de-Lomagne, son of the wealthy leather merchant Dominique de Fermat and his second wife Claire, née de Long. No records exist of his early education or of his path into mathematics. He studied law at the universities of Toulouse and Orléans, where he was awarded the degree of bachelor of civil of law in 1631. In the same year, he married his fourth cousin removed, Louise de Long.
During a sojourn in Bordeaux, at the end of the 1620s, he actively participated in the scientific circle there around Étienne d'Espagnet. Early versions of mathematical texts, including parts of his restoration of Apollonius's Plane loci, were circulated among members such as Pierre Prades and Jean Beaugrand. After his return to Toulouse, Fermat briefly studied Galileo's Dialogo and produced work on the topic of free fall.
Fermat's career was in law and civic administration. By the time of his marriage he had purchased the offices of conseiller to the Parliament of Toulouse and of commissioner of requests to the palace. In the course of his civic career he reached the highest councils, eventually dividing his time between Toulouse and the court of justice in Castres.
In Toulouse he met Pierre de Carcavi, a fellow conseiller, who shared his interest in mathematical science. When Carcavi went to Paris to take up the post of royal librarian, he provided a glowing account of Fermat to Mersenne. Thus persuaded to initiate a correspondence with the Toulouse mathematician, Mersenne asked Fermat to share his findings with him and other members of his circle.
Relations with Descartes were less equanimous. When Beaugrand, in May 1637, sent galley proofs of the Dioptrics to Fermat, the recipient soon reported that the work contained two considerable errors. In particular, the derivation of the sine law of refraction assumed more than Descartes acknowledged. Over the following months arguments were traded, both men being supported by their respective camps: Fermat principally by Beaugrand, Étienne Pascal, and Roberval; Descartes principally by Mydorge. In November 1637, Roberval and Mersenne solicited Fermat to send his method for determining maxima and minima and tangents to curved lines to them in Paris.