In mathematics, a cofinite subset of a set 
  
    
      
        X
      
    
    {\displaystyle X}
  
 is a subset 
  
    
      
        A
      
    
    {\displaystyle A}
  
 whose complement in 
  
    
      
        X
      
    
    {\displaystyle X}
  
 is a finite set. In other words, 
  
    
      
        A
      
    
    {\displaystyle A}
  
 contains all but finitely many elements of 
  
    
      
        X
        .
      
    
    {\displaystyle X.}
  
 If the complement is not finite, but is countable, then one says the set is cocountable.
 These arise naturally when generalizing structures on finite sets to infinite sets, particularly on infinite products, as in the product topology or direct sum. 
 This use of the prefix "co" to describe a property possessed by a set's complement is consistent with its use in other terms such as "comeagre set". 
 The set of all subsets of 
  
    
      
        X
      
    
    {\displaystyle X}
  
 that are either finite or cofinite forms a Boolean algebra, which means that it is closed under the operations of union, intersection, and complementation. This Boolean algebra is the finite–cofinite algebra on 
  
    
      
        X
        .
      
    
    {\displaystyle X.}
  
 A Boolean algebra 
  
    
      
        A
      
    
    {\displaystyle A}
  
 has a unique non-principal ultrafilter (that is, a maximal filter not generated by a single element of the algebra) if and only if there exists an infinite set 
  
    
      
        X
      
    
    {\displaystyle X}
  
 such that 
  
    
      
        A
      
    
    {\displaystyle A}
  
 is isomorphic to the finite–cofinite algebra on 
  
    
      
        X
        .
      
    
    {\displaystyle X.}
  
 In this case, the non-principal ultrafilter is the set of all cofinite sets.
 The cofinite topology (sometimes called the finite complement topology) is a topology that can be defined on every set 
  
    
      
        X
        .
      
    
    {\displaystyle X.}
  
 It has precisely the empty set and all cofinite subsets of 
  
    
      
        X
      
    
    {\displaystyle X}
  
 as open sets. As a consequence, in the cofinite topology, the only closed subsets are finite sets, or the whole of 
  
    
      
        X
        .
      
    
    {\displaystyle X.}
  
 Symbolically, one writes the topology as
  This topology occurs naturally in the context of the Zariski topology. Since polynomials in one variable over a field 
  
    
      
        K
      
    
    {\displaystyle K}
  
 are zero on finite sets, or the whole of 
  
    
      
        K
        ,
      
    
    {\displaystyle K,}
  
 the Zariski topology on 
  
    
      
        K
      
    
    {\displaystyle K}
  
 (considered as affine line) is the cofinite topology. The same is true for any irreducible algebraic curve; it is not true, for example, for 
  
    
      
        X
        Y
        =
        0
      
    
    {\displaystyle XY=0}
  
 in the plane.
 The double-pointed cofinite topology is the cofinite topology with every point doubled; that is, it is the topological product of the cofinite topology with the indiscrete topology on a two-element set.  It is not T0 or T1, since the points of each doublet are topologically indistinguishable.  It is, however, R0 since topologically distinguishable points are separated.  The space is compact as the product of two compact spaces; alternatively, it is compact because each nonempty open set contains all but finitely many points.
 For an example of the countable double-pointed cofinite topology, the set 
  
    
      
        
          Z
        
      
    
    {\displaystyle \mathbb {Z} }
  
 of integers can be given a topology such that every even number 
  
    
      
        2
        n
      
    
    {\displaystyle 2n}
  
 is topologically indistinguishable from the following odd number 
  
    
      
        2
        n
        +
        1
      
    
    {\displaystyle 2n+1}
  
.  The closed sets are the unions of finitely many pairs 
  
    
      
        2
        n
        ,
        2
        n
        +
        1
        ,
      
    
    {\displaystyle 2n,2n+1,}
  
 or the whole set.  The open sets are the complements of the closed sets; namely, each open set consists of all but a finite number of pairs 
  
    
      
        2
        n
        ,
        2
        n
        +
        1
        ,
      
    
    {\displaystyle 2n,2n+1,}
  
 or is the empty set.
 The product topology on a product of topological spaces 
  
    
      
        ∏
        
          X
          
            i
          
        
      
    
    {\displaystyle \prod X_{i}}
  
 has basis 
  
    
      
        ∏
        
          U
          
            i
          
        
      
    
    {\displaystyle \prod U_{i}}
  
 where 
  
    
      
        
          U
          
            i
          
        
        ⊆
        
          X
          
            i
          
        
      
    
    {\displaystyle U_{i}\subseteq X_{i}}
  
 is open, and cofinitely many 
  
    
      
        
          U
          
            i
          
        
        =
        
          X
          
            i
          
        
        .
      
    
    {\displaystyle U_{i}=X_{i}.}
  

 The analog without requiring that cofinitely many factors are the whole space is the box topology.
 The elements of the direct sum of modules 
  
    
      
        ⨁
        
          M
          
            i
          
        
      
    
    {\displaystyle \bigoplus M_{i}}
  
 are sequences 
  
    
      
        
          α
          
            i
          
        
        ∈
        
          M
          
            i
          
        
      
    
    {\displaystyle \alpha _{i}\in M_{i}}
  
 where cofinitely many 
  
    
      
        
          α
          
            i
          
        
        =
        0.
      
    
    {\displaystyle \alpha _{i}=0.}
  

 The analog without requiring that cofinitely many summands are zero is the direct product.