For a given year, the IF of a scientific journal is the average number of citations of each article published in this journal (citations made in other journals as well as itself) during the period of the previous 2 years
FI = citation received in 2019 from articles published in 2017 and 2018 / Number of articles published in 2017 and 2018
I would just like to highlight the followings to support the above answers:
Answers given above define journal impact factor (IF) based on two-year citation window. In addition to this, one can also find IF based on five-year citation window, defined in the similar fashion except the time frame. However, two-year frame is the most popular measure.
As Anton says, it is important to consider the number of 'Citable articles' for the denominator of the equation. Not all articles published in a journal are citable. For example, 'erratum' published in a journal cannot be considered as a citable document. So, they must be excluded from the calculations.