Using light curves obtained by the K2 mission, we study the relation between stellar rotation and magnetic activity with special focus on stellar flares. Our sample comprises 56 bright and nearby M dwarfs observed by K2 during campaigns C0-C18 in long- and short-cadence mode. We derive rotation periods for 46 M dwarfs and measure photometric activity indicators such as amplitude of the rotational signal, standard deviation of the light curves, and the basic flare properties (flare rate, flare energy, flare duration, and flare amplitude). We found 1662 short-cadence flares, 363 of which have a long-cadence counterpart with flare energies of up to $5.6cdotp10^{34}$erg. The flare amplitude, duration, and frequency derived from the short-cadence light curves differ significantly from those derived from the long-cadence data. The analysis of the short-cadence light curves results in a flare rate that is 4.6 times higher than the long-cadence data. We confirm the abrupt change in activity level in the rotation-activity relation at a critical period of ~10d when photometric activity diagnostics are used. This change is most drastic in the flare duration and frequency for short-cadence data. Our flare studies revealed that the highest flare rates are not found among the fastest rotators and that stars with the highest flare rates do not show the most energetic flares. We found that the superflare frequency ($Egeq5cdotp10^{34}$erg) for the fast-rotating M stars is twice higher than for solar like stars in the same period range. By fitting the cumulative FFD, we derived a power-law index of $alpha=1.84 pm 0.14$, consistent with previous M dwarf studies and the value found for the Sun.