Using light curves obtained by the K2 mission, we study the relation between stellar rotation and magnetic activity with a 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, flare amplitude). We found 1662 short cadence flares of which 363 have a long cadence counterpart with flare energies up to 5.6*10^34^erg. The flare amplitude, duration and flare frequency derived from the short cadence LCs differ significantly from the ones derived from the long cadence data. The analysis of the short cadence light curves results in a 4.6 times higher flare rate than the long cadence data. We confirm the abrupt change of the 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 the flare frequency for short cadence data. Our flare studies revealed that the highest flare rates are not found among the fastest rotators and that the stars with the highest flare rates do not show the most energetic flares. We found a ~2 times larger superflares frequency (>5*10^34^erg) for the fast rotating M stars than for solar like stars in the same period range. By fitting the cumulative flare frequency distribution we derived a power-law index of alpha=1.84+/-0.14 consistent with previous M dwarf studies and the value found for the Sun.