A t-test is a statistical hypothesis test used to compare the means of two groups when the sample size is small or the population variance is unknown, while a z-test is used when the sample size is large and the population variance is known.