Formally, a homotopy between two continuous functions *f* and *g* from a
topological space *X* to a topological space *Y* is defined to be a
continuous function *H* : *X* × [0,1] → *Y* from the product of the space *X* with the unit interval [0,1]
to *Y* such that, for all points *x* in *X*, *H*(*x*,0)=*f*(*x*)
and *H*(*x*,1)=*g*(*x*).

Being homotopic is an equivalence relation on the set of all continuous functions from *X* to *Y*.
This homotopy relation is compatible with function composition in the following sense: if *f*_{1}, *g*_{1} : *X* → *Y* are homotopic, and *f*_{2}, *g*_{2} : *Y* → *Z* are homotopic, then their compositions *f*_{2} o *f*_{1} and *g*_{2} o *g*_{1} : *X* → *Z* are homotopic as well.

Given two spaces *X* and *Y*, we say they are **homotopy equivalent** if there exist continuous maps *f* : *X* → *Y* and *g* : *Y* → *X* such that *g* o *f* is homotopic to the identity map id_{X} and *f* o *g* is homotopic to id_{Y}.

The maps *f* and *g* are called **homotopy equivalences** in this case.

Intuitively, two spaces *X* and *Y* are homotopy equivalent if they can be transformed into one another by bending, shrinking and expanding operations. For example, a solid disk or solid ball is homotopy equivalent to a point, and **R**^{2} - {(0,0)} is homotopy equivalent to the unit circle *S*^{1}. Those spaces that are homotopy equivalent to a point are called **contractible**.

Homotopy equivalence is important because in algebraic topology most concepts cannot distinguish homotopy equivalent spaces: if *X* and *Y* are homotopy equivalent, then

- if
*X*is path-connected, then so is*Y* - if
*X*is locally path-connected, then so is*Y* - if
*X*is simply connected, then so is*Y* - the homology and cohomology groups of
*X*and*Y*are isomorphic - if
*X*and*Y*are path-connected, then the fundamental groups of*X*and*Y*are isomorphic, and so are the higher homotopy groups

More abstractly, one can appeal to category theory concepts. One can define the **homotopy category**, whose objects are topological spaces, and whose morphisms are homotopy classes of continuous maps. Two topological spaces *X* and *Y* are isomorphic in this category if and only if they are homotopy-equivalent.

A **homotopy invariant** is any function on spaces, (or on mappings), that respects the relation of *homotopy equivalence* (resp. *homotopy*); such invariants are constitutive of *homotopy theory*. Of course one could have foundational objection to a function whose domain is the collection of all topological spaces.

In practice homotopy theory is carried out by working with CW complexes, for technical convenience; or in some other reasonable category.

Especially in order to define the fundamental group, one needs the notion of **homotopy relative to a subspace**. These are homotopies which keep the elements of the subspace fixed. Formally: if *f* and *g* are continuous maps from *X* to *Y* and *K* is a subset of *X*, then we say that *f* and *g* are homotopic relative *K* if there exists a homotopy *H* : *X* × [0,1] → *Y* between *f* and *g* such that *H*(*k*,*t*) = *f*(*k*) for all *k*∈*K* and *t*∈[0,1].

In geometric topology - for example in knot theory - the idea of isotopy is used to construct equivalence relations. For example, when should two knots be considered the same? We take two knots *K _{1}* and

For , the homotopy classes actually form a homotopy group. If , then this group is Abelian. (For a proof of this, note that in two dimensions or greater, two homotopies can be "rotated" around each other.)