Thomas Gainsborough’s early masterpiece, Mr and Mrs Andrews (c1750), has long been read as a celebration of that pivotal moment in mid-Georgian Britain when man managed to wrestle nature to its knees and tell it what to do. To one side of the painting are the recently married Robert and Frances Andrews, a lucky young couple handsomely dressed in a rustle of linen, satin and soft leather. Significantly, though, the pair are posing not in the library or hall of their manor house but out in the grounds, in the well-worked, wheat-covered bit of Suffolk’s loamy Stour valley that provides the capital on which their combined fortune depends. In the far distance you can just make out the tower of All Saints’ Church where this alliance between two local landowning families – one gentry, one trade – has recently been settled to everyone’s satisfaction.

Gainsborough painted the happy couple, not to mention their happy acres, with such a zesty freshness that it’s a shock to learn that, until the picture was bought by the National Gallery in 1960, Mr and Mrs Andrews was kept hidden away by the family, like some mad aunt in the attic. James Hamilton, the author of this richly humane biography of the artist, thinks he knows why. Hamilton suggests that, far from being a servile recorder of other people’s good fortune, young Tom Gainsborough was never afraid to blurt out inconvenient truths, much in the manner of his great hero William Hogarth. Why else would he have introduced into his lyrical landscape a pair of plebeian donkeys, corralled in an enclosure? Hamilton believes this is a deliberate jibe about the matrimonial trap into which Robert Andrews, who was an old schoolmate from Sudbury Grammar, has blundered. Then there’s the billowy way in which Andrews’s gunpowder bag and gun have been rendered to make them look like a set of swollen genitalia, waiting to seed the fertile ground. Oddest of all, though, a space on Mrs Andrews’s lap has been left blank, with only the canvas peeping through. Art historians have long argued about whether Gainsborough was reserving room for a baby, a lapdog or a dead pheasant. But for Hamilton, who is as astute a reader of Gainsborough’s smuttiness as he is of his blazing talent, what matters is the faint scratch of a design that you can just make out in the empty space: “Frances Andrews has a drawing of a penis on her skirt.”

Facebook Twitter Pinterest The statue of Thomas Gainsborough in Sudbury, Suffolk. Photograph: Alamy

Gainsborough could make these behind-the-Hanoverian-bike-shed jokes about the way that land, money, class and sex were imbricated in the Stour valley because he had grown up just over the low, dipping horizon of his own picture. Born in 1727 to a bad branch of a good family in the Suffolk cloth trade, he knew all about the urge to get and spend in the age of speculation. His milliner father failed to prosper and at one point a rich relation was obliged to buy the family home in order to avoid the shame of Thomas and his seven siblings being put out on the street. Being caught up in such a psychodrama at close quarters, Hamilton suggests, meant that young Tom was in prime position to observe the micro-expressions of resentment and relief that flickered across the faces of the grownups. It was this attention to the twitch of muscle and tendon that fitted the lad up beautifully for the profession of “face painter”.

Still, the real reason why he chose to develop the portraiture side of his practice rather than landscape was because it paid better. Even in his sullen, broken-down hometown of Sudbury, there were always enough vain men in tricorn hats who prodded each other’s pigs on market day and married each other’s daughters to sustain a profitable practice. It was now that Gainsborough honed his skill at doing fancy waistcoats, catching the way that expensive silk strained over comfortable stomachs in a fused symbol of conspicuous consumption. It is from this era that Mr and Mrs Andrews hails, and you feel that Gainsborough, with his literacy in cloth, has been able to price up Frances’s extravagant puff of a cornflower blue skirt with a single sweep of his eye.

A habit of steely calculation worked less well when it came to choosing a wife. Margaret Burr was the illegitimate daughter of the 3rd Duke of Beaufort with £200 a year settled on her. Handy certainly, but not exactly handsome, especially when you take into account Gainsborough’s knack of over-spending to keep up with his clients (surrounded by plush velvet and silk, it was hard to settle for serge). Knowing her husband to be a spendthrift like his father, Margaret insisted on Tom handing over his considerable earnings, out of which she grudgingly allowed him pocket money. It all sounds horribly humiliating, which is perhaps why, on one of his solo trips to London, he returned to the marital home with a violent dose of the clap.

There is another element to the painter: his secretive private life of week-long hangovers and a penchant for petticoats

By this point that marital home was a grand terrace address in Bath, where Gainsborough had set himself up as portraitist to the great, the good and the notorious. He quadrupled his prices and pumped up his work so that, along with the head-and-shoulder portraits of hypochondriac bores, he did 8ft tall whoppers of visiting celebrities. And no painting was more whopper-ish than his 1760 full-length portrait of Ann Ford, a young gentlewoman who insisted on performing in public as a musician and singer, much to her family’s dismay. He shows Ford as a seductive presence in a sinuous shimmer of silvery silk. She fiddles with her hair with one hand, while with the other she caresses the beloved guitar perched on her daringly crossed knee (women’s laps were clearly still a thing for Gainsborough, a whole decade after Mrs Andrews). An extra frisson comes from knowing that Ford is currently being romantically stalked by a silly old peer called Lord Jersey. The sumptuous portrait, just this side of shocking, was designed as an advertisement, a prominent prop in Gainsborough’s showroom to remind the punters that he was so much more than a spa town hack.

Gainsborough’s life has long been told as a struggle between money and art, between the “cursed face business” that covered his mushrooming expenses and the “landskips” that were his true love. Hamilton has too much integrity to upend this argument simply to make a splash. But what he does suggest in this astute yet generous book is that there is a third element to the painter’s life that explains why he continued with a branch of art that he maintained bored him. This last layer is his secretive private life which, Hamilton says, consisted of week-long hangovers, a penchant for “petticoat” and the habit of scribbling smutty letters to his male friends expressing regret for his most recent bit of bad behaviour.

It was these kinds of urgent passions and recurring penances that bound him to his sitters, the randy dukes as well as the wool merchants, the flirtatious actresses as well as the disapproving pin-thin wives. He could paint all these people because there was no petulant desire or secret shame to which he was not also party. And it was this recognition of the universal human game that drew him back again and again to people over places, to Mr and Mrs Andrews sitting on the left side of the frame with their expensive clothes and oddly posed bodies rather than the bosky glades and serene sandbanks that rippled out behind them.

• Gainsborough: A Portrait is published by Weidenfeld & Nicolson. To order a copy for £21.25 (RRP £25) go to bookshop.theguardian.com or call 0330 333 6846. Free UK p&p over £10, online orders only. Phone orders min p&p of £1.99.