BackgroundDespite its important role in education, significant gaps remain in the literature on homework. Notably, there is a dearth of understanding regarding how homework effects vary across different subjects, how student backgrounds may moderate its effectiveness, what the optimal amount and distribution of homework is, and how the causal impact of homework can be disentangled from other associations. AimsThis study examines the different effects of homework frequency and duration on student achievement in both mathematics and science while adopting a causal inference probabilistic framework. SampleOur data consists of a nationally representative sample of 4118 Irish eighth grade students, collected as part of TIMSS 2019. MethodsWe employ an extension of a causal inference machine learning model called Bayesian Causal Forests that allows us to consider the effect of homework on achievement in mathematics and science simultaneously. By investigating the impacts of both homework frequency and duration, we discern the optimal frequency and duration for homework in both subjects. Additionally, we explore the potential moderating role of student socioeconomic backgrounds. ResultsDaily homework benefitted mathematics achievement the most, while three to four days per week was most effective for science. Short-duration assignments proved equally as effective as longer ones in both subjects. Notably, students from advantaged socioeconomic backgrounds did not gain more from homework. ConclusionsThese findings can guide policies aimed at enhancing student outcomes while promoting a balance between academic responsibilities and extracurricular activities.