In this paper we present a result which establishes a connection between the theory of compact operators and the theory of iterated function systems. For a Banach space \(X\), \(S\) and \(T\) bounded linear operators from \(X\) to \(X\) such that \(\Vert S\Vert , \Vert T\Vert <1\) and \(w\in X\), let us consider the IFS \(\mathcal S _{w}=(X,f_{1},f_{2})\), where \(f_{1},f_{2}:X\rightarrow X\) are given by \(f_{1}(x)=S(x)\) and \(f_{2}(x)=T(x)+w\), for all \(x\in X\). On one hand we prove that if the operator \(S\) is compact, then there exists a family \((K_{n})_{n\in \mathbb N }\) of compact subsets of \(X\) such that \(A_{\mathcal S _{w}}\) is not connected, for all \(w\in X-\bigcup _{n\in \mathbb N } K_{n}\). On the other hand we prove that if \(H\) is an infinite dimensional Hilbert space, then a bounded linear operator \(S:H\rightarrow H\) having the property that \(\Vert S\Vert <1\) is compact provided that for every bounded linear operator \(T:H\rightarrow H\) such that \(\Vert T\Vert <1\) there exists a sequence \((K_{T,n})_{n}\) of compact subsets of \(H\) such that \(A_{\mathcal S _{w}}\) is not connected for all \(w\in H-\bigcup _{n}K_{T,n}\). Consequently, given an infinite dimensional Hilbert space \(H\), there exists a complete characterization of the compactness of an operator \(S:H\rightarrow H\) by means of the non-connectedness of the attractors of a family of IFSs related to the given operator. Finally we present three examples illustrating our results.