What you get out of it does depend on what level of test you take.
I would recommend using FamilyTreeDNA as they have the largest Y-DNA database, but you may find smaller companies as well that can tell you your haplogroup.
The lower level Y-DNA tests are STR (single tandem repeat) tests. The technicalities don't really matter, but these are areas on the Y-chromosome which are found to be useful markers to distinguish individuals/groups. With STR testing you will get a basic haplogroup (e.g. R-M269 or I-M253), but this haplogroup may be thousands of years old.
If you want a more refined haplogroup, you will need to do SNP testing (Single Nucleotide Polymorphisms). At FTDNA, although you could order SNP packs you are much better served by ordering the Big Y-700. This test includes 700 STRs and thousands of SNPs. With this test you can potentially get a very recent haplogroup from the last couple hundred years.
With either test you will get match lists. Most of the matches will not match your surname, as they may have branched off before surnames were adopted. At low levels (37 markers) you may have tens to thousands of matches. At higher levels (111 markers) you will probably only have a handful, or sometimes no matches. The more markers you match with someone, the more closely you are probably related, and the more markers you test the more confident you can be the match is real.
In my case and my mum's paternal line (I tested a male cousin on my mum's side), I started out with the Y-37 test, and have since upgraded to Big Y-700. It is costly, but has been well worth it in both cases, helping to narrow down an illegitimacy a few generations back on my mum's side, and confirming a theorized link to a similar surname (that just could not be proved with paper trail alone due to sparsity of parish registers in the period of interest).