 Ansari was educated at St John's Beaumont School and came through the Surrey academy system, having represented the county before he turned nine and also representing England at U15 (a team he also captained), U17 and U19 level.He was awarded an academic scholarship to Hampton School and read politics and sociology at Trinity Hall, Cambridge, graduating with a double-first.In 2016 he completed a 40,000 word Masters dissertation on the 1960s American civil rights group, the Deacons for Defense and Justice, being awarded his master's degree in history with Distinction at the end of the year by Royal Holloway, University of London.