We present matRad, an open source software for three-dimensional radiation treatment planning of intensity modulated photon, proton, and carbon ion therapy. matRad is developed for educational and research purposes; it is entirely written in MATLAB. A first beta release is available for download. The toolkit features a highly modular design with a set of individual functions modeling the entire treatment planning workflow based on a segmented patient CT. All algorithms, e.g. for ray tracing, photon/proton/carbon dose calculation, fluence optimization, and multileaf collimator sequencing, follow well-established approaches and operate on clinically adequate voxel and bixel resolution. Patient data, as well as base data for all required computations, is included in matRad. We achieve computation times of 60-100s (60-400s) for realistic patient cases including photon (particle) dose calculation and fluence optimization. Memory consumption ranges between 0.2GB and 2.2GB. Dose distributions of a treatment planning study for a phantom and prostate patient case considering multiple radiation modalities are shown. Both the computational and dosimetric results encourage a future use of matRad in an educational and scientific setting.