Australian Medicare Number Validation

Australian Medicare card numbers consist of 11 digits structured as follows:

First digit should be in the range 2-6
Digits are weighted (1,3,7,9,1,3,7,9)
Issue Number
Indicates how many times the card has been issued
Individual Reference Number (IRN)
The IRN appears on the left of the cardholder's name on the medicare card and distinguishes the individuals named on the card.

The IRN is not always considered part of the card number, but it is essential that it be included on Medicare claim forms.


It can be hard to find a definitive reference to the algorithm on the Medicare site. At the time of writing it could be found in this document:

Try It!

Sample Code

//   ValidateMedicareNumber
//     Checks medicare card number for validity
//     using the published checksum algorithm.
//     Returns: true if the number is valid, false otherwise.
//     Note - this expects 11 digits including the IRN.  
//     To validate numbers without IRNs, change the length
//     check to 10 digits.
//      Source:
//      Author: Guy Carpenter
//     License: The author claims no rights to this code.
//              Use it as you wish.

function ValidateMedicareNumber($MedicareNo)
    $medicareNo = preg_replace("/[^\d]/", "", $MedicareNo);

    // Check for 11 digits
    $length = strlen($medicareNo);
    if ($length==11) {
        // Test leading digit and checksum
        if (preg_match("/^([2-6]\d{7})(\d)/", $medicareNo, $matches)) {
            $base = $matches[1];
            $checkDigit = $matches[2];
            $sum = 0;
            $weights = array(1,3,7,9,1,3,7,9);
            foreach ($weights as $position=>$weight) {
                $sum += $base[$position] * $weight;
            return ($sum % 10) == intval($checkDigit);
    return false;

comments powered by Disqus