The algorithms used by the ATLAS Collaboration during Run 2 of the Large Hadron Collider to identify jets containing $b$-hadrons are presented. The performance of the algorithms is evaluated in the simulation and the efficiency with which these algorithms identify jets containing $b$-hadrons is measured in collision data. The measurement uses a likelihood-based method in a sample of highly enriched in $t\bar{t}$ events. The topology of the $t \to W b$ decays is exploited to simultaneously measure both the jet flavour composition of the sample and the efficiency in a transverse momentum range from 20 GeV to 600 GeV. The efficiency measurement is subsequently compared with that predicted by the simulation. The data used in this measurement, corresponding to a total integrated luminosity of 80.5 fb$^{-1}$, were collected in proton-proton collisions during the years 2015 to 2017 at a centre-of-mass energy $\sqrt{s}=$ 13 TeV. By simultaneously extracting both the efficiency and jet flavour composition, t his measurement significantly improves the precision compared to previous results, with uncertainties ranging from 1% to 8% depending on the jet transverse momentum.