One has acquired more Olympic medals than any other athlete in history. The other was knocked out of the Games after just 250 seconds. But Michael Phelps and Ashley McKenzie, the 23-year-old British No 1 judoka, have one thing in common: both have attention deficit hyperactivity disorder (ADHD), as does another high-profile Olympian, British gymnast Louis Smith, who this week helped win the first British men's gymnastics team medal for a century.

Suddenly, a condition that is hugely stigmatised and still controversial, is unexpectedly in the spotlight. It raises several interesting questions. Does ADHD hinder or help sporting success? And can the Olympics offer a positive legacy for people suffering from it?

Phelps, the American swimmer with a record-breaking 19 Olympic medals to his name, is probably the most famous person in the world with ADHD, the top behavioural disorder in Britain, which is estimated to affect 2-5% of children and young people. For Phelps, a gangly, hyperactive child who was diagnosed with the condition aged nine, the swimming pool was a sanctuary, a place to burn off excess energy. His mother, Debbie, once recalled being told by a teacher: "Your son will never be able to focus on anything." It's interesting that the boy who was unable to concentrate at school would sit for four hours at swimming meets waiting to compete in five minutes of races.

Louis Smith has spoken of how gymnastics was an outlet for his tremendous energy, and taught him discipline and manners. But Ashley McKenzie's story is perhaps most dramatic of all. Expelled from three schools and placed in a psychiatric unit aged 11 because his mother was unable to cope, McKenzie also served time in a young offenders' institute. He credits judo with saving him from prison, and in a recent BBC documentary called it a "mad booster" to his life, giving him "a pavement instead of walking on the road".

"I don't want to be looked at as, 'He's got ADHD and he's the bad person.' I've changed now," he said.

But it is not as simple as sport rescuing him. McKenzie served three bans from judo for drinking and fighting, and on the last night of the Team GB training camp before the Olympics, he went out to celebrate his 23rd birthday and told a stranger at a bar: "I'm gonna smash your face in." His ADHD may bequeath him energy but his sporting career is actually a hindrance to tackling his condition: he cannot take the medication he needs to treat his ADHD because it contains substances banned by the sporting authorities – hence his struggle to control his behaviour.

More athletes will almost certainly be undiagnosed or keeping it quiet, such as Adam Kreek, a Canadian rower who won gold in Beijing, and two years later began talking openly about his condition. "I found that the disorder isn't a negative infliction, but it gives positive energy as well," Kreek, who is now a motivational speaker, said in 2010. Diagnosed aged six, he believes anyone with ADHD can train their mind to channel their "incredible" energy. As well as a good diet and family support, he found "rowing to be an outlet to control my ADHD".

ADHD can be a confusing condition because people may be fidgety and unable to focus and yet – as Phelps so spectacularly proved – are capable of concentrating intently on an activity they find rewarding. Children with the disorder, says Andrea Bilbow, founder and chief executive of ADDISS, a charity and support service for ADHD, are often brilliant at computer games. Psychiatrists say that this "hyperfocusing" is a relatively common feature in individuals with ADHD.

Athletes like Phelps and McKenzie do not, however, have special powers via their condition. Bilbow believes it is actually significantly harder for people with ADHD to become elite athletes. "Having ADHD doesn't mean you're going to be a great sportsperson," she says. "Your ADHD isn't going to get you there, it's hard work that will. ADHD is not a contributor towards success but equally it is not a barrier to success."

People with ADHD, which is a developmental disorder, may find they have poor problem-solving skills, and struggle with timekeeping, and organising and motivating themselves, explains Bilbow. This may suggest that adapting to the discipline demanded by athletic training is tough for those with ADHD and yet Bilbow believes many with the condition find sport gives them the kind of immediate rewards and sense of achievement they need to build confidence and resilience.

After his early exit in the judo, McKenzie has vowed to come back stronger in Rio in 2016. Bilbow hopes McKenzie can get the extra help he will need in the coming years. She works with parents with children with ADHD and believes more could find sport a constructive way of managing the condition, rather than being preoccupied with academic success. Her two sons, Max and Joe, both have ADHD: Max, who is 29, finds an outlet for his energy in elite kayaking while Joe, who is 25, is currently an Olympic volunteer. Her advice to parents? "Find your child's island of competence and invest in it heavily."

Bilbow has noticed that children with ADHD may have their sporting opportunities curtailed as punishment for their behaviour, as McKenzie found. Bilbow knows of a brilliant young footballer with ADHD who was barred from representing his school because of his conduct in lessons.

Many teachers and schools, she believes, still scoff at the disorder, believing there are only naughty children – and bad parents. The concept of role models can seem an overused cliche but the Olympians with ADHD may really inspire a generation of athletes who once would have been written off. "Parents can be saying to kids who are having a miserable time in school, 'Look, Michael Phelps had ADHD and he worked really hard. Ashley McKenzie has been in a young offenders' institute but he didn't give up,'" says Bilbo. "That's the message we've got to give kids."