We consider the problem of finding \(A_2(n,\{d_1,d_2\})\) defined as the maximal size of a binary (non-linear) code of length n with two distances \(d_1\) and \(d_2\) . Binary codes with distances d and \(d+2\) of size \(\sim \frac{n^2}{\frac{d}{2}(\frac{d}{2}+1)}\) can be obtained from 2-packings of an n-element set by blocks of cardinality \(\frac{d}{2}+1\) . This value is far from the upper bound \(A_2(n,\{d_1,d_2\})\le 1+{n\atopwithdelims ()2}\) proved recently by Barg et al. In this paper we prove that for every fixed d (d even) there exists an integer N(d) such that for every \(n\ge N(d)\) it holds \(A_2(n,\{d,d+2\})=D(n,\frac{d}{2}+1,2)\) , where \(D(n,\frac{d}{2}+1,2)\) is the maximal size of a 2- \((n,\frac{d}{2}+1,1)\) packing. In other words, an optimal code is a translation of some constant-weight code. We prove also estimates on N(d) for \(d=4\) and \(d=6\) .