This happens in the first chapter of the book. Tom goes swimming instead of going to school and he thinks he's going to get away with it. But then his cousin Sid tells on him and that's how Aunt Polly finds out.
Aunt Polly had sewn Tom's collar shut that morning. Tom figured out that he could just undo the stitches, go swimming, and then stitch it up again. And that's what he did. But then Sid pointed out that the thread is now black whereas Aunt Polly used white in the morning. Once that is pointed out, Aunt Polly knows what Tom did.