The tangent space matrix of a vertex on a surface (also called TBN matrix, due to its components), is a matrix that converts from coordinates expressed in tangent space to coordinates expressed in object space (being the later, the base in which all vertex coordinates are expressed).
There are some operations between vectors (like illumination calculations) that are nonsense if they are not expressed in the same basis; Thanks to the TBN matrix, a surface can have fine details (like bumpy texture, notches, etc) using textures containing normal maps (whose normals are expressed in tangent space); those normals can be converted from tangent space to object space so the illumination calculations can be done. The next figure shows how the effect of normal mapping looks over a simple surface.
From tangent space to object space
The column vectors of this matrix T, B y N, are the vectors tangent, bitangent (or more commonly known as binormal) and normal to the vertex over which the calculation is done. These vectors are expressed in object coordinates. It’s been said before, with this matrix one can change coordinates from tangent space basis to object space basis.
From object space to tangent space
The inverse matrix is able to convert coordinates from object space to tangent space.
The inverse of a matrix is a complex calculation. But, when the angles of a triangle equal the angles of its mapped triangle in texture space (there is no deformation), the calculated tangent space matrix is orthogonal, and so, its inverse matrix is simply its transposed. This is a great simplification.
TBN matrix calculation
The calculation of the TBN matrix is done with some equations that know a triangle’s vertexes and their texture coordinates the derivation of this matrix is going to be done with respect to. The orientation of its basis vectors (T,N and N) will depend on the orientation of the texture mapping. For a detailed explanation of this process, you can visit the article Derivation of the Tangent Space Matrix, by Jakob Gath, and edited by Soren Dreijer. Also related with its how to use it, there is also the article Bump Mapping Using CG (3rd Edition) by Soren Dreijer.