Informally speaking, the baryon number of a given particle is one third of the difference between the number of quarks it is comprised and the number of anti-quarks.
Why one third? According to the laws of strong interaction there cannot be any bare color charge, i.e. the total color charge of a particle has to be zero ('white'), cf. confinement. This can only be achieved by either putting together a quark of a color with an antiquark of the corresponding anti-color, giving a meson with baryon number 0, or by combining three quarks (or three anti-quarks) to a baryon (or an anti-baryon, resp.) with baryon number 1 (or -1, resp.). (Another, exotic, possibility is e.g. 4 quarks and 1 anti-quark, which has actually been observed in 2003, cf. pentaquark.)
Particles without any quarks or antiquarks (these are called leptons) of course have baryon number 0.
The baryon number is conserved in all interactions of the Standard Model. 'Conserved' means that the sum of the baryon number of all incoming particles is the same as the sum of the baryon numbers of all particles resulting from the reaction.
The, still hypothetical, idea of supersymmetry allows for the changing of a hadron in a lepton, thus violating the conservation of baryon and lepton number.