Validated methods of identifying childhood maltreatment (CM) in primary and secondary care data are needed. We aimed to create the first externally validated algorithm for identifying maltreatment using routinely collected healthcare data. Comprehensive code lists were created for use within GP and hospital admissions datasets in the SAIL Databank at Swansea University working with safeguarding clinicians and academics. These code lists build on and refine those previously published to include an exhaustive set of codes. Sensitivity, specificity and positive predictive value of previously published lists and the new algorithm were estimated against a clinically assessed cohort of CM cases from a child protection service secondary care-based setting—‘the gold standard’. We conducted sensitivity analyses to examine the utility of wider codes indicating Possible CM. Trends over time from 2004 to 2020 were calculated using Poisson regression modelling. Our algorithm outperformed previously published lists identifying 43–72% of cases in primary care with a specificity ≥ 85%. Sensitivity of algorithms for identifying maltreatment in hospital admissions data was lower identifying between 9 and 28% of cases with high specificity (> 96%). Manual searching of records for those cases identified by the external dataset but not recorded in primary care suggest that this code list is exhaustive. Exploration of missed cases shows that hospital admissions data is often focused on the injury being treated rather than recording the presence of maltreatment. The absence of child protection or social care codes in hospital admissions data poses a limitation for identifying maltreatment in admissions data. Linking across GP and hospital admissions maximises the number of cases of maltreatment that can be accurately identified. Incidence of maltreatment in primary care using these code lists has increased over time. The updated algorithm has improved our ability to detect CM in routinely collected healthcare data. It is important to recognize the limitations of identifying maltreatment in individual healthcare datasets. The inclusion of child protection codes in primary care data makes this an important setting for identifying CM, whereas hospital admissions data is often focused on injuries with CM codes often absent. Implications and utility of algorithms for future research are discussed.