Hacking a computer is about finding vulnerabilities. You look for loopholes and you find a way to exploit them. Hacking a human brain, it turns out, is not so different - and, over the past two decades, technology companies have learned to play you like a fiddle.
According to Dr Mark Griffiths, the UK's leading addiction expert, social media firms such as Facebook and Snapchat have developed an arsenal of techniques to keep us glued to their products. He has identified seven "hooks", drawn from 31 years studying the gambling industry, which drive "habitual use" - not addiction in the clinical sense, but frequent enough that other parts of your life may suffer.
"I don't think Facebook or Instagram are deliberately trying to addict people," says Dr Griffiths, "but what they are trying to do is to maximise the time people are on their network, because that relates to the advertising they can raise."
No wonder the average person now touches their phone screen over 2,500 times a day.
Of course, not all time spent online is time wasted. But if you find yourself tapping and scrolling when you should be working or relaxing, you might want to watch out for these techniques designed to make your smartphone unputdownable.
Imagine you're in Las Vegas playing a slot machine. You're down to your last few dollars but you just keep going. Every time you pull the lever, you don't know what you'll get - and every time you think: this time I'll win.
Psychologists call this an "intermittent reward schedule", and it's one of the most basic and powerful addiction techniques we know of. It's unreliable enough to keep you guessing, but rewarding enough to keep you hoping.
Now look to your smartphone. That motion you make when you drag your thumb down the screen to refresh a feed? It's similar to pulling the lever on a slot machine.
Loren Brichter, the 33-year-old software developer who came up with the 'pull-to-refresh' gesture, has since admitted regretting ever inventing it, saying he has spent "many months and years" thinking about whether it benefits humanity.
Facebook, Instagram, Twitter and the like are full of mechanisms by which we can receive validation and approval from others when we check our notifications (more intermittent rewards).
The problem comes when we start to judge ourselves by the tokens we receive or modify our opinions according to what we can see is popular. Many people are reluctant to give a post their 'thumbs-up' if they can see nobody else has done so.
The ultimate expression of online affirmation is the Facebook 'Like' button. When Justin Rosenstein first built it in 2007 - originally called "the Awesome button" - he wanted to create a "path of least resistance" to express positivity to your friends. It worked: engagement soared and Facebook gained a new stream of data about its users' preferences.
But now Rosenstein condemns 'Likes' as "bright dings of pseudo-pleasure" that have helped create "a problem at a civilisation scale".
In a 1968 study of gambling habits, people who had already bet on a horse were much more likely to rate it as a winner than those who had not yet parted with their money. This "sunk-cost bias" leads us to justify decisions we have already made, even if we unconsciously regret them.
That's why social media sites want you to build a profile that grows as you post: the more time and effort we invest, the harder we will find it to consider the idea that we might be wasting our time. This sense of investment is well-exploited in mobile games that offer micro-rewards for logging in every day.
The fear of missing out (or 'fomo' for short) is a common reason for over-indulging in social media. It is associated with greater engagement with social networking, lower life satisfaction and even with dangerous usage (such as while driving).
"I've got three 'screenagers'," says Dr Griffiths, "and when we go on holiday without wifi, they are climbing the walls because they don't know what's going on."
To prevent fomo (or perhaps to capitalise upon it), many social media sites now regularly prod users with 'see what you've missed' messages. The effect is to constantly bring you back into the network when you're not paying attention, reminding you that interesting conversations are going on behind your back and that, maybe, if you said the right things, you too could be this popular…
Every moment, we are bombarded with stimuli and, by necessity, the brain filters most of it out. So it takes novel sensations to break through that filter - what psychologists call the principle of salience.
Social media firms use piercing tones, bright colours and attractive artwork to pull you from whatever you're doing and towards their app.
The most effective way to exploit salience is the 'push' notification. Pioneered by Apple in 2009, these buzz-vibrate alerts have transformed how often we check our smartphones.
Any social media site that gives us a number or a rating by which to judge ourselves also compel some of us to compete for the highest rating. The most common such score is the follower count; imagine Twitter or Instagram without knowing how much more or less popular you are than everyone else.
Dr Griffiths' research has also found that frequent selfie-takers say they "feel lost" when their friends' online follower count exceeds their own and that social competition is one of the main reasons some people take selfies at all.
When someone else likes or follows us we are more likely to return the favour and may even feel obligated to do so - which is why apps are always sure to tell us when friends have interacted with our posts.
This principle reached its peak with the invention of read receipts - dreaded little notes on messaging apps that say something like: "Your friend read this message at 17:35". They force you to respond as quickly as you can for fear of insulting the other person.
Yet they create such anxiety that in a survey of Danish students, 82pc said they routinely left messages deliberately unopened so as not to trigger a receipt.
How do I quit?
Ryan Tubridy has been raving about the benefits of a digital detox on his radio show, while Selena Gomez, the most-followed celebrity on Instagram, has said a 90-day break from her smartphone did wonders for her mental health.
Start by downloading an app which tracks your usage. "Giving people non-judgemental information about their own behaviour often initiates self-appraisal," says Dr Griffiths.
Try Moment (on iOS) or Antisocial (on Android), or use a parenting app such as Eset Parental Control or Samsung Marshmallow to set time limits for individual apps. Never let yourself use any single app for more than an hour a day. To limit distraction, set aside daily periods of non-screen time. Turn your phone off or set it to 'do not disturb' on evenings and weekends. Make an absolute rule of never having it out at the dinner table or during personal meetings.
And buy a wristwatch (not a smart watch!): Dr Griffiths says "one of the most common reasons for looking at a smartphone or a tablet is to check the time".
If you have kids, track their use too and set hard limits for how long they can spend on gaming and social media apps (the recommended rule is two hours per day). Always insist they hand you their phones before bedtime and never let them have a gaming device in their own room.
The most important thing, though, is simply to learn to enjoy time away from screens.