Nursing facilities provide skilled nursing and rehabilitative care to patients for short stays and custodial care to patients for long stays. The type of nursing facility stay (short-or long-term) is a potentially important risk factor and health outcome in health services research and is informative from both medical and fiscal perspectives. The purpose of this study was to develop and validate an algorithm to identify the use of nursing facility services and differentiate short-from long-term care using Medicare claims data. We used claims data for a 5% sample of Medicare beneficiaries to develop an algorithm to detect the use of nursing facility services and to distinguish between short-and long-term stays. We tested this algorithm using residency status from Medicaid long-term care claims for dually eligible beneficiaries and using residency status from the Medicare Current Beneficiary Survey (MCBS). Among 1,694,051 beneficiaries included in the baseline cohort, 25.6% had some indication of nursing facility residency. Using our algorithm, 59.8% of beneficiaries using any nursing facility care were classified as long-term residents. Validation of the algorithm against Medicaid long-term care claims and MCBS yielded high sensitivity and specificity. To our knowledge, this is the first paper to present a