Scientists will also be able to use this technique to trace the transmission of the disease between hospitals throughout the world, informing healthcare systems on how best to prevent future outbreaks.
A world-wide collaboration of scientists, including researchers at the University of Bath and the Wellcome Trust Sanger Institute, analysed more than 150 million DNA sequences from 62 samples of the antibiotic-resistant bacteria MRSA (methicillin-resistant Staphylococcus aureus) to identify differences in genetic information between the samples.
Their results, published in the prestigious journal Science, show this technique is powerful enough to narrow down the source of an infection to a single hospital ward.
Dr Ed Feil from the University of Bath's Department of Biology & Biochemistry explained: "When bacteria reproduce they can sometimes make mistakes when copying their DNA. This can cause new strains to evolve as an infection is spread from person to person.
"The DNA of the bacteria is therefore a bit like a fingerprint - by comparing small changes in the DNA sequence of bacteria isolated from different patients, we are able to identify where an infection has come from and trace how it has spread."
Previous techniques of identifying strains of bacteria can only detect a small proportion of the total number of changes in the DNA, and this missing information makes it difficult to track transmission over very short time-scales.
This is the first study to use a state-of-the-art technique which allows the detection of all the mutations within the DNA of many strains of bacteria simultaneously.
The research will also help to reveal the DNA mutations responsible for antibiotic resistance, allowing scientists to develop new ways of tackling super-bugs such as MRSA.
"Telling the difference between isolates within one species is fundamentally important in the development of public health strategies," said Stephen Bentley, from the Wellcome Trust Sanger Institute, who was one of the co-authors on the paper with Dr Feil.
"It allows researchers and public health officials to see how infections are spread: from person to person; from hospital to hospital; from country to country."
It is hoped that understanding where and how the infection has spread between patients will help inform healthcare systems how best to prevent future outbreaks from turning into epidemics.